EntityFieldFactory.Create bug?

Posts   
 
    
TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 29-Aug-2008 18:08:10   

Hi,

I think there's a bug in the EntityFieldFactory.Create(string objectName, string fieldName) method. Things work just fine when I use this method for normal entities.

But today I struggled quite some hours to identify this "bug". I use inheritance (based on the discriminator column). At runtime I try to identify a field of an inherited entity, to use for my dynamic ConcurrencyPredicateFactory. (A timestamp field called Version).

The line of code I use is the following:


EntityField2 timestampField =
             (EntityField2)EntityFieldFactory.Create(entity.GetType().Name, TIME_STAMP_FIELD_NAME)

Where TIME_STAMP_FIELD_NAME is a constant that holds the value "Version"

This line works just fine for alle normal entities or the base entity. But for the derived classed, this line of code produces the following error:

The field 'Version' isn't known in the element 'Em3xxEntity' Parameternaam: elementFieldName

This means that in following example the first 2 would be ok, but the third one fails (because Em3xx is derived from Device)


         EntityField2 timestampField = (EntityField2)EntityFieldFactory.Create("FuelEntity", "Version");

         EntityField2 timestampField2 = (EntityField2)EntityFieldFactory.Create("Device", "Version");

         EntityField2 timestampField3 = (EntityField2)EntityFieldFactory.Create("Em3xx", "Version");

This is the end of the stacktrace...


   bij SD.LLBLGen.Pro.ORMSupportClasses.FieldInfoProviderBase.GetFieldInfo(String elementName, String elementFieldName)
   bij EMGroup.Galantis.BL.Core.FactoryClasses.EntityFieldFactory.Create(String objectName, String fieldName) in 

Can you please help me out for this one?

Kind regards, TomV

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Aug-2008 07:28:30   

Hi Tom, I think, this is by design. However I think this workaround should work:

EntityField2 timestampField = (EntityField2)EntityFieldFactory.Create( 
     entity.Fields[TIME_STAMP_FIELD_NAME].ContainingObjectName, 
     TIME_STAMP_FIELD_NAME);

As you see, _ContainingObjectName _is useful where the entity belongs to an inheritance, this also work if the entity doesn't.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 30-Aug-2008 10:53:51   

What's the llblgen pro version, build date etc. ?

Is the version field mapped in the derived entity or in the supertype/root?

Frans Bouma | Lead developer LLBLGen Pro
TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 01-Sep-2008 08:44:49   

Otis wrote:

What's the llblgen pro version, build date etc. ?

Is the version field mapped in the derived entity or in the supertype/root?

Hi Otis, sorry I always forget to post this..

  • It's Version 2.5 Final (December 5th, 2007)
  • The version field is mapped on the root type, so it's available as an inherited field.

Hi Daelmo, your work around seems to work.

Although I think it should have worked the way I used the code.

Kind regards, TomV

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Sep-2008 10:47:07   

You are using an old runtime library version, would you please try using the latest available version, just to be sure it has nothing to do with the old version.

TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 01-Sep-2008 11:06:55   

Ok Walaa, I was still running the version I downloaded when we bought our license. I will download the version 2.6 and let you know the result...

Kind regards, TomV

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Sep-2008 11:36:06   

You can also download the latest release of v.2.5

TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 01-Sep-2008 11:42:03   

Too late, I already converted my project to 2.6... Not a bad thing at all...

It took me some time, adding templates, plugins, parameters in config files, but things build again...

  • The problem still exists in version 2.6 (August 18th, 2008 )

Regards, TomV

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 01-Sep-2008 18:05:39   

Fixed in next build. Although the code you use isn't really maintainable. Consider a utility routine which produces an entity based on EntityType and obtain the field from there, also using an entity field index, because names are not compile time checked of course.

Frans Bouma | Lead developer LLBLGen Pro
TomV
User
Posts: 76
Joined: 31-Jan-2008
# Posted on: 01-Sep-2008 18:14:01   

Otis wrote:

Fixed in next build. Although the code you use isn't really maintainable. Consider a utility routine which produces an entity based on EntityType and obtain the field from there, also using an entity field index, because names are not compile time checked of course.

Hi Otis,

thanks for the answer.

I only use this approach for my concurrency handling. All my tables their last column is a timestamp (name: Version) column on SQL Server. I created a plugin + template for LLBLGenPro which makes sure that all my entities implement the interface IIdAndVersion.

This way I can use the constant TIME_STAMP_FIELD_NAME safely. But this is the only place, at all other places I use the available enums or field index.

Again, thanks for your fast help guys!

Kind regards, TomV