Extending DTO template

Posts   
 
    
KS
User
Posts: 55
Joined: 08-Aug-2006
# Posted on: 03-Nov-2006 15:05:08   

<Environment Info> Adpater pattern LLBL Designer version 2.0.0.0 LLBLGen Pro .NET 2.0 ORM Support Classes 2.0.0.60904 .Net 2.0 VS.NET 2005 </Environment Info>

Hi Frans

I have used DTO template following thread has discussed. http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6261

Its really helpful, thanks. I have been tweaking that template to meet our requirements. Now I want DTO to include the "fields on related fields" of Entity to be included in DTO. Can you provide some hint , how to go about it.

I know if you will, its always good to know why you want to do it . Here's my answer to it. I am trying to create a composite DTO(for 1-1 relations).

I know its not part of your official release, still I would appreciate if you can provide some clue to hit it at right area.

Your help is always appreciated simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 03-Nov-2006 16:05:41   

You can cheat from the already existsing templates. For example check the EntityAdapter.template

You will find the following line:


<[Foreach RelatedEntity OneToOne CrLf]><[If Not MappedFieldRelationIsHidden]>       private <[RelatedEntityName]>Entity _<[CaseCamel MappedFieldNameRelation]>;<[EndIf]><[NextForeach]>

Which defines the private member field mapped to a related entity. you can trace it's usage inside the template. (search for other places where "RelatedEntity" is used)

Also for FieldsOnRelatedFields, check the EntityIncludeAdapter.template


<[ Foreach RelatedEntityField  CrLf]> 
        /// <summary> Gets <[ If Not IsReadOnly ]>/ Sets <[ EndIf ]>the value of the related field this.<[ MappedFieldNameRelation ]>.<[ RelatedEntityFieldName ]>.</summary>
        public virtual <[If GenerateAsNullableType]>Nullable<<[TypeOfField]>><[Else]><[TypeOfField]><[EndIf]> <[ MappedFieldNameRelatedField ]>
        {
            get
            {
                <[RelatedEntityName]>Entity relatedEntity = this.<[ MappedFieldNameRelation ]>;
                if(relatedEntity!=null)
                {
                    return relatedEntity.<[ RelatedEntityFieldName ]>;
                }
                else
                {
                    return (<[If GenerateAsNullableType]>Nullable<<[TypeOfField]>><[Else]><[TypeOfField]><[EndIf]>)TypeDefaultValue.GetDefaultValue(typeof(<[If GenerateAsNullableType]>Nullable<<[TypeOfField]>><[Else]><[TypeOfField]><[EndIf]>));
                }
            }
<[ If Not IsReadOnly ]>         set
            {
                <[RelatedEntityName]>Entity relatedEntity = this.<[ MappedFieldNameRelation ]>;
                if(relatedEntity!=null)
                {
                    relatedEntity.<[ RelatedEntityFieldName ]> = value;
                }               
            }<[ EndIf ]>
        }<[ NextForeach ]>  

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 03-Nov-2006 16:06:00   

You want all fields of related entities or just the fields you mapped as fields on related fields?

Frans Bouma | Lead developer LLBLGen Pro
KS
User
Posts: 55
Joined: 08-Aug-2006
# Posted on: 03-Nov-2006 16:21:09   

Waala :: You can cheat from the already existsing templates

Great mind think alike simple_smile . I already started doing them. I am very close. However Casecamel is creating some problem for me rage , its not generating properly.

_<[CaseCamel MappedFieldNameRelatedField]>

Frans You want all fields of related entities or just the fields you mapped as fields on related fields?

I just want "fields on related fields".

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 03-Nov-2006 17:32:49   

What kind of error do you get with casecamel?

Frans Bouma | Lead developer LLBLGen Pro
KS
User
Posts: 55
Joined: 08-Aug-2006
# Posted on: 03-Nov-2006 18:19:33   

The generated code looks like "CaseCamelAdvertiserName" instead of "advertiserName"

no runtime errors, only that generated code is not correct.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 06-Nov-2006 20:46:42   

Very strange, as it is a valid statement. I'll see what I can find with a debug test.

Frans Bouma | Lead developer LLBLGen Pro
KS
User
Posts: 55
Joined: 08-Aug-2006
# Posted on: 07-Nov-2006 04:08:22   

Do let me know the results of your test, coz for now I have got [_VariableName] in my DTO code for all private fields("fields on related fieds") all over the place. Until someone catches me for that I am fine, after that its you simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 07-Nov-2006 11:53:50   

I can reproduce this error. Looking into it.

(edit) the parser made a mistake: it didn't take into account all nametoken statements for casecamel. I've updated that list as some others were missing too simple_smile

Fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro