Modifiying a property in a subclass

Posts   
 
    
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 28-Apr-2005 12:37:55   

Hi there at the forum,

in the adapter Subclasses template, a property is defined for each related entity. I need to be able to insert my own code into the getters and setters of these properties.

Currently, such properties are already defined in the SubClasses such as


public new virtual MyOrderEntity Order
{
     get{}
     set{}
}

In the documentation, there is no "User code regions" defined for this purpose. Also I am unable to override these properties in the subclass flushed , should this be possible.

Any Suggestions would be greatly appreciated!

Best regards

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 28-Apr-2005 16:34:31   

Which particular code do you want to add to those properties? (so I have a better overview)

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 28-Apr-2005 18:02:19   

Hi Otis,

In the application I work on, it is often reqquired that when you create a record (an order for example), that information related to the record at the time it was created (information about the customer for example) need to be saved together with the Order. The purpose of this is that cutomer data can change, and the order created has to be according to conditions at the time the order was created and not any other time. (The table order in my case has a few columns that relate to order itself and most of the columns are related to the cutomer). In my case, records can be created in a number of positions (gui, automatic, etc.) and I would like to hand the Order object a Customer object and have it select the data available. Currently, the order object has a Cutomer property, yet I have to create a seperate property for this purpose.

There are also a lot of issues where it would be quite convinient to hand an object instead of assigning values to properties (it is very tempting in Selfservicing) where no DB-access is needed and all data needed is encapsulated in a single object.

So much for the explanation.

I would really appreciate any thoughts you might have on this.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Apr-2005 13:24:15   

eugene wrote:

Hi Otis,

In the application I work on, it is often reqquired that when you create a record (an order for example), that information related to the record at the time it was created (information about the customer for example) need to be saved together with the Order. The purpose of this is that cutomer data can change, and the order created has to be according to conditions at the time the order was created and not any other time. (The table order in my case has a few columns that relate to order itself and most of the columns are related to the cutomer). In my case, records can be created in a number of positions (gui, automatic, etc.) and I would like to hand the Order object a Customer object and have it select the data available. Currently, the order object has a Cutomer property, yet I have to create a seperate property for this purpose.

But if you alter the derived entity template (for adapter), you can add the user region yourself to the property.

There are also a lot of issues where it would be quite convinient to hand an object instead of assigning values to properties (it is very tempting in Selfservicing) where no DB-access is needed and all data needed is encapsulated in a single object.

You could add a method for that 'SetCustomer'.

Frans Bouma | Lead developer LLBLGen Pro
eugene
User
Posts: 85
Joined: 05-Oct-2004
# Posted on: 29-Apr-2005 15:32:34   

Dear Otis,

I just checked the template for derivedEntityAdapter.template.

Are you suggesting something like the follwing?


<[Foreach RelatedEntity ManyToOne]><[If Not MappedFieldRelationIsHidden]>
/// <summary>
/// </summary>
[Browsable(false)]
public new virtual My<[RelatedEntityName]>Entity <[MappedFieldNameRelation]>
{
    get
    {
    return (My<[RelatedEntityName]>Entity)base.<[MappedFieldNameRelation]>;
    }
    set
    {
    base.<[MappedFieldNameRelation]> = value;
                <[ UserCodeRegion "EntityMember" ]>
                // __LLBLGENPRO_USER_CODE_REGION_START EntityMember
                // __LLBLGENPRO_USER_CODE_REGION_END
                <[ EndUserCodeRegion ]>
    }
}
<[EndIf]><[NextForeach]>

A question: Do I need a seperate region pro member or is it possible to have a region defined at multiple positions within an emmitted document?

Best regards

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Apr-2005 20:38:02   

eugene wrote:

Dear Otis,

I just checked the template for derivedEntityAdapter.template.

Are you suggesting something like the follwing?


<[Foreach RelatedEntity ManyToOne]><[If Not MappedFieldRelationIsHidden]>
/// <summary>
/// </summary>
[Browsable(false)]
public new virtual My<[RelatedEntityName]>Entity <[MappedFieldNameRelation]>
{
    get
    {
    return (My<[RelatedEntityName]>Entity)base.<[MappedFieldNameRelation]>;
    }
    set
    {
    base.<[MappedFieldNameRelation]> = value;
                <[ UserCodeRegion "EntityMember" ]>
                // __LLBLGENPRO_USER_CODE_REGION_START EntityMember
                // __LLBLGENPRO_USER_CODE_REGION_END
                <[ EndUserCodeRegion ]>
    }
}
<[EndIf]><[NextForeach]>

A question: Do I need a seperate region pro member or is it possible to have a region defined at multiple positions within an emmitted document?

The region's contents in the current file is retrieved using the name of the region so if you have multiple times the same region, it will end up in not that great code.

You can pass in a usercoderegion name based on a value like MappedFieldNameRelation, using another version of UserCodeRegion, see the SDK docs for details on that statement.

For example I'd suggest here:


<[Foreach RelatedEntity ManyToOne]><[If Not MappedFieldRelationIsHidden]>
/// <summary>
/// </summary>
[Browsable(false)]
public new virtual My<[RelatedEntityName]>Entity <[MappedFieldNameRelation]>
{
    get
    {
    return (My<[RelatedEntityName]>Entity)base.<[MappedFieldNameRelation]>;
    }
    set
    {
    base.<[MappedFieldNameRelation]> = value;
                <[ UserCodeRegion StringValueEquals "MappedFieldNameRelation" "($VALUE)Setter" ]>
                // __LLBLGENPRO_USER_CODE_REGION_START <[UserCodeRegionName]>
                // __LLBLGENPRO_USER_CODE_REGION_END
                <[ EndUserCodeRegion ]>
    }
}
<[EndIf]><[NextForeach]>

Frans Bouma | Lead developer LLBLGen Pro