Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Custom Templates> VB.NET DTO Template for v2.5
 

Pages: 1
Custom Templates
VB.NET DTO Template for v2.5
Page:1/1 

  Print all messages in this thread  
Poster Message
DavidArcher
User



Location:
Orlando, FL, USA
Joined on:
24-Oct-2007 01:55:44
Posted:
3 posts
# Posted on: 14-Nov-2007 14:00:49.  
After looking through the forums, I found a DTO template for C# but not one for VB. Here is the existing C# template translated over to VB for those who would like to use this in a VB.NET project.

Frans, any change of getting these DTO templates included in the next release since we have both languages now? :-)

Code:

Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Runtime.Serialization
Imports <[RootNamespace]>.EntityClasses

Namespace <[RootNamespace]>.DtoClasses
    ''' <summary>
    ''' DTO class for the entity '<[CurrentEntityName]>'.
    ''' </summary>
    <Serializable()> _
    Public <[If UsePartialClasses]>Partial <[EndIf]>Class <[CurrentEntityName]>Dto<[ If IsSubType ]>
        Inherits <[ SuperTypeName ]>Dto<[ EndIf]>

        #Region "Class Member Declarations"
<[Foreach EntityField CrLf]>        Private _<[CaseCamel EntityFieldName]> As <[If IsNullable]><[If IsValueType]>Nullable(Of <[TypeOfField]>)<[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]><[NextForeach]>
        #End Region
    
        ''' <summary>
        ''' CTor
        ''' </summary>
        Public Sub New()
        
        End Sub

        ''' <summary>
        ''' CTor which initializes the DTO with values from its corresponding entity
        ''' </summary>
        ''' <param name="entityInstance">The entity instance which holds the values for this DTO</param>
        Public Sub New(ByVal entityInstance As <[CurrentEntityName]>Entity)
<[Foreach EntityField CrLf]>            _<[CaseCamel EntityFieldName]> = entityInstance.<[EntityFieldName]><[NextForeach]>
        End Sub
                
        ''' <summary>
        ''' Creates a new entity instance and copies over the values of this DTO
        ''' </summary>
        Public <[If IsSubType]>Overloads <[EndIf]>Function ToEntity() As <[CurrentEntityName]>Entity
            Return ToEntity(new <[CurrentEntityName]>Entity())
        End Function
        
        ''' <summary>
        ''' Copies over the values of this DTO into the entity passed in.
        ''' </summary>
        Public <[If IsSubType]>Overloads <[EndIf]>Function ToEntity(ByVal toFill As <[CurrentEntityName]>Entity) As <[CurrentEntityName]>Entity
<[Foreach EntityField CrLf]><[If Not IsReadOnly]>            toFill.<[EntityFieldName]> = _<[CaseCamel EntityFieldName]><[EndIf]><[NextForeach]>
<[If IsSubType]>            MyBase.ToEntity(toFill)
<[ EndIf]>Return toFill
        End Function

<[Foreach EntityField CrLf]>
        ''' <summary>The <[EntityFieldName]> property of the Entity <[CurrentEntityName]></summary>
        Public <[If EntityFieldOverrides]>Overrides<[Else]>Overridable<[EndIf]> <[If IsReadOnly]>ReadOnly <[EndIf]>Property [<[EntityFieldName]>]() As <[If IsNullable]><[If IsValueType]>Nullable(Of <[TypeOfField]>)<[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]>
            Get
                Return _<[CaseCamel EntityFieldName]>
            End Get<[If Not IsReadOnly]>
            Set(value As <[If IsNullable]><[If IsValueType]>Nullable(Of <[TypeOfField]>)<[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]>)
                _<[CaseCamel EntityFieldName]> = value
            End Set<[EndIf]>    
        End Property
<[NextForeach]>
    End Class
End Namespace
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14447 posts
# Posted on: 14-Nov-2007 15:15:36.  
Thanks for sharing.

  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37313 posts
# Posted on: 15-Nov-2007 12:05:52.  
We'll add both to the 3rd party section in the customer area. Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37313 posts
# Posted on: 19-Nov-2007 12:00:27.  
I've added links to both to the FAQ.

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
jelling
User



Location:

Joined on:
26-Oct-2007 21:37:18
Posted:
22 posts
# Posted on: 21-Jan-2008 01:21:24.  
Thanks for the great template.

One thing I learned while implementing it was that web services don't expose read-only properties. This makes sense for updates but it was hurting my cause when I was returning data to the client. What I did was remove the read-only parts of the template so that my properties remained read only in the DAL but were exposed via the DTOs. Our current plan is to do our updates via parameterized methods so hopefully this will work out.

Here's my revised <ForEach> section:

Code:

<[Foreach EntityField CrLf]>
        ''' <summary>The <[EntityFieldName]> property of the Entity <[CurrentEntityName]></summary>
        Public <[If EntityFieldOverrides]>Overrides<[Else]>Overridable<[EndIf]> Property [<[EntityFieldName]>]() As <[If IsNullable]><[If IsValueType]>Nullable(Of <[TypeOfField]>)<[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]>
            Get
                Return _<[CaseCamel EntityFieldName]>
            End Get
            Set(value As <[If IsNullable]><[If IsValueType]>Nullable(Of <[TypeOfField]>)<[Else]><[TypeOfField]><[EndIf]><[Else]><[TypeOfField]><[EndIf]>)
                _<[CaseCamel EntityFieldName]> = value
            End Set
        End Property
<[NextForeach]>


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.