HasEntityField and Inheritance

Posts   
 
    
takb
User
Posts: 150
Joined: 12-Mar-2004
# Posted on: 21-Sep-2006 08:54:20   

I've got a custom include template that creates an additional constructor on entities that have a specific field for concurrency control. This has been working fine until it came to working with inherited entities. The problem is that my concurrency field is on the base class table but I still want this behaviour on all derived entities. Here is the code that I use:

    <[If HasEntityField "ROWLOCKKEY"]>
        <[If Not StringValueEquals CustomPropertyName "DoNotCreateConcurrencyPredicateFactory"]>
        /// <summary> CTor</summary>
        /// <param name="iD">PK value for <[CurrentEntityName ]> which data should be fetched into this <[ CurrentEntityName ]> object</param>
        /// <param name="rowVersion">Concurrency Control field for this entity. Providing this value will set the underlying DbValue property. Used for updating entities without fetching first</param>
        /// <remarks>The entity is not fetched by this constructor. Use a DataAccessAdapter for that.</remarks>
        public <[ CurrentEntityName ]>Entity(System.Int32 iD, System.Int32 rowVersion):this(iD)
        {
            // Assign both the current value and the DbValue of ROWLOCKKEY. This is used to maintain concurrency control when updating entities 
            // without first fetching that entity.
            Fields[(int)<[ CurrentEntityName ]>FieldIndex.ROWLOCKKEY].ForcedCurrentValueWrite(rowVersion, rowVersion);
            Fields.AcceptChanges();
            IsNew = false;
        }
        <[EndIf]>
    <[EndIf]>

The problem is that "HasEntityField" is not true while processing a subclass entity even though that entity will indeed have this field from its base class. Can you suggest a way that I can test whether the base entity has the field? I just can't seem to figure out what combination of template elements to use to achieve this.

takb
User
Posts: 150
Joined: 12-Mar-2004
# Posted on: 21-Sep-2006 09:56:17   

It's ok. I've figured it out. Instead of <[ If HasEntityField "ROWLOCKKEY" ]> I can use this:

<[ Foreach EntityField IncludeInherited ]> 
    <[ If StringValueEquals EntityFieldName "ROWLOCKKEY" ]>

Although I would suggest that a good enhancement would be to add IncludeInherited as an optional parameter to HasEntityField.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39786
Joined: 17-Aug-2003
# Posted on: 21-Sep-2006 10:03:14   

I'll add that to the todo list simple_smile

Frans Bouma | Lead developer LLBLGen Pro