DTO Templates feedback

Posts   
 
    
carlosga
User
Posts: 31
Joined: 02-Jun-2004
# Posted on: 28-Jun-2008 23:18:05   

I'm goingo to start a new project ( just to learn some new things like WPF and WCF and for fun simple_smile ) and i will be using LLBLGen Pro for the persistence layer.

The client is going to access some data services using WCF, and i'm thinking on use the DTO pattern to decouple the UI from the LLBLGen Pro generated entities, is this the preferred way or should i use the LLBLGen generated entities directly ?? simple_smile

I have downloaded some DTO templates i found in the forum and modified them to:

  1. Make the DTO's not having any reference to the llblgen entities.
  2. Generate a basic Mapper class to convert from dto->entity and entity->dto

Before continue with the development i want to "hear" some feedback from people that knows LLBLGen Pro better than me ( just a newbie simple_smile ) on the templates to be sure they are fine.

I think that i should made some modification to handle the IsNew and IsDirty properties of the LLBLGen entities but i'm not sure if that will be really needed simple_smile

The templates are attached to the post.

Thanks in advance !!!

P.D: Sorry for my bad english simple_smile

Attachments
Filename File size Added on Approval
Templates.zip 3,352 28-Jun-2008 23:18.21 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 30-Jun-2008 09:44:38   

carlosga wrote:

I'm goingo to start a new project ( just to learn some new things like WPF and PCF and for fun simple_smile ) and i will be using LLBLGen Pro for the persistence layer.

The client is going to access some data services using WCF, and i'm thinking on use the DTO pattern to decouple the UI from the LLBLGen Pro generated entities, is this the preferred way or should i use the LLBLGen generated entities directly ?? simple_smile

You can use entities without a problem with WCF (see the manual (Adapter -> Distributed systems -> WCF) for details about what to do wink ). If your client is a java client, you of course have to opt for DTO's. If you are writing a .NET client, you can use entities and use the features build in, like validation, authorization etc. simple_smile

I have downloaded some DTO templates i found in the forum and modified them to:

  1. Make the DTO's not having any reference to the llblgen entities.
  2. Generate a basic Mapper class to convert from dto->entity and entity->dto

Before continue with the development i want to "hear" some feedback from people that knows LLBLGen Pro better than me ( just a newbie simple_smile ) on the templates to be sure they are fine.

I think that i should made some modification to handle the IsNew and IsDirty properties of the LLBLGen entities but i'm not sure if that will be really needed simple_smile

The templates are attached to the post.

Thanks for sharing! simple_smile . The thing with IsNew and IsDirty is that when the DTO comes back, you want the existing entity (if available) to update with the values. So the best way to do this is I think with fetching the entity and then setting the properties with the data from the DTO. This automatically sets the IsDirty flag. If the DTO is new, you obviously won't find an entity and you fill a new one with the data.

Frans Bouma | Lead developer LLBLGen Pro
carlosga
User
Posts: 31
Joined: 02-Jun-2004
# Posted on: 30-Jun-2008 10:16:42   

Otis wrote:

You can use entities without a problem with WCF (see the manual (Adapter -> Distributed systems -> WCF) for details about what to do wink ).

I will take a look at that section of the documentation, thanks !!

Otis wrote:

If your client is a java client, you of course have to opt for DTO's. If you are writing a .NET client, you can use entities and use the features build in, like validation, authorization etc. simple_smile

it's going to be a .NET Client ( WPF ), let's java to be as far as possible of me xD

Otis wrote:

Thanks for sharing! simple_smile . The thing with IsNew and IsDirty is that when the DTO comes back, you want the existing entity (if available) to update with the values. So the best way to do this is I think with fetching the entity and then setting the properties with the data from the DTO. This automatically sets the IsDirty flag. If the DTO is new, you obviously won't find an entity and you fill a new one with the data.

Ok, i was thinking on avoid the need of fetching again the entity before doing the update, that is why i was thinking in having the IsNew and IsDirty properties in the DTO as well, and map them in both directions.

I'm going to read the Adapter section of the documentation, before doing nothing simple_smile

Thanks again simple_smile

HcD avatar
HcD
User
Posts: 214
Joined: 12-May-2005
# Posted on: 24-Feb-2009 15:39:52   

[quotenick="carlosga"] The templates are attached to the post. quote]

Could you repost them. I want to take a look but see nothing in the attach ...

thnx ! Sven.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 24-Feb-2009 15:42:11   

[quotenick="HcD"]

carlosga wrote:

The templates are attached to the post. quote]

Could you repost them. I want to take a look but see nothing in the attach ...

thnx ! Sven.

See the startpost, click the paperclip wink

Frans Bouma | Lead developer LLBLGen Pro
Jazz
User
Posts: 63
Joined: 12-Aug-2005
# Posted on: 21-Mar-2009 19:47:19   

i like your templates. did some small modifications like making the mappers assemble methods extension methods.

anybody knows how to skip the "Via" Relations for the DTO creation?

regards, andré

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Mar-2009 04:29:07   

At this code:

#region · Relation Fields ·
<[Foreach RelatedEntity OneToMany CrLf]><[If Not MappedFieldRelationIsHidden]>      private ObservableCollection<<[RelatedEntityName]>> <[CaseCamel MappedFieldNameRelation]>;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity ManyToMany CrLf]><[If Not MappedFieldRelationIsHidden]>     private ObservableCollection<<[RelatedEntityName]>> <[CaseCamel MappedFieldNameRelation]>;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity ManyToOne CrLf]><[If Not MappedFieldRelationIsHidden]>      private <[RelatedEntityName]> <[CaseCamel MappedFieldNameRelation]>;<[EndIf]><[NextForeach]>
<[Foreach RelatedEntity OneToOne CrLf]><[If Not MappedFieldRelationIsHidden]>       private <[RelatedEntityName]> <[CaseCamel MappedFieldNameRelation]>;<[EndIf]><[NextForeach]>
#endregion

.... delete this:

<[Foreach RelatedEntity ManyToMany CrLf]><[If Not MappedFieldRelationIsHidden]>     private ObservableCollection<<[RelatedEntityName]>> <[CaseCamel MappedFieldNameRelation]>;<[EndIf]><[NextForeach]>

And delete this block:

<[Foreach RelatedEntity ManyToMany CrLf]><[If Not MappedFieldRelationIsHidden]>
/// <summary>
/// Gets the EntityCollection with the related entities of type '<[RelatedEntityName]>Entity' which are related to this entity via a relation of type 'm:n'.
/// If the EntityCollection hasn't been fetched yet, the collection returned will be empty.
/// </summary>
[DataMember]
public virtual ObservableCollection<<[RelatedEntityName]>> <[MappedFieldNameRelation]>
{
    get
    {
        if (this.<[CaseCamel MappedFieldNameRelation]> == null)
        {
            this.<[CaseCamel MappedFieldNameRelation]> = new ObservableCollection<<[RelatedEntityName]>>();
        }
                return this.<[CaseCamel MappedFieldNameRelation]>;
    }
}<[EndIf]><[NextForeach]>

Or simply, hide the m:n relations at your project.

David Elizondo | LLBLGen Support Team
Jazz
User
Posts: 63
Joined: 12-Aug-2005
# Posted on: 23-Mar-2009 20:24:08   

Thanks David,

much appreciated!

Regards, André