EntityFields2 with dublicated field names

Posts   
 
    
cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 11-Jul-2011 11:52:11   

Hello,

in old LLBL version EntityFields2 was able to accept fields with the same name. For example:

EntityFields2 fields2 = new EntityFields2(2); fields2.DefineField(FormFields.ChangeDate, 0); fields2.DefineField(DocumentFields.ChangeDate, 1);

However its not the case anymore in the new version. This code now result to exception:

System.ArgumentException : An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFields2.set_Item(Int32 index, IEntityField2 value) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFields2.DefineField(IEntityField2 fieldToAdd, Int32 indexInFields) at ESG.Shared.UnitTests.PrintingManagement.CoreDALTests.TestGetExtraFieldCurrentValue() in CoreDALTests.cs: line 292

Why this was changed? As I understand, fields with the same name but different index still can exists, or?

If fields are added twice from the same table, it also can have different Alias, which may be set later..

It will be quite hard to find all the places, where it is used in this way... rage Any suggestions? Should I start digging through all code base or its a bug in LLBL?

thank you.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Jul-2011 14:17:21   

Please try adding an alias to at least one of these fields.

cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 11-Jul-2011 16:50:27   

Walaa wrote:

Please try adding an alias to at least one of these fields.

I know this option simple_smile Just we have a lot of code, where field first added to EntityFields2 collection and alias set after it.. It worked with 1.0.2005.. simple_smile

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Jul-2011 18:19:24   

Which runtime library version (build number) are you using?

cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 12-Jul-2011 07:40:05   

Walaa wrote:

Which runtime library version (build number) are you using?

File version: 3.1.11.427 Product version: 3.1.11.0427

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Jul-2011 09:27:17   

Just to rule out the possibility, could you please try the latest version.

cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 12-Jul-2011 09:55:45   

Walaa wrote:

Just to rule out the possibility, could you please try the latest version.

Version - Build: 3.1.0.0 07012011

System.ArgumentException : An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at SD.LLBLGen.Pro.ORMSupportClasses.EntityFields2.set_Item(Int32 index, IEntityField2 value) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\EntityFields2.cs: line 1197 at ESG.Shared.UnitTests.PrintingManagement.CoreDALTests.TestDoubleEntityField2() in CoreDALTests.cs: line 282

UnitTest code:

[Test] [ExpectedException(typeof(ArgumentException))] public void TestDoubleEntityField2() { EntityFields2 entityFields = new ESGEntityFields(2); entityFields[0] = DocumentFields.ChangeDate; entityFields[1] = FormFields.ChangeDate; }

One additional suggestion: write somewhere latest version in the start page or near download link simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Jul-2011 10:52:01   

This is not a bug, but a feature (yes), or better: it's a result of a feature: name lookup is more efficient as it's not doing a linear search, but uses an index cache. This has been the case since 2.0.

it can handle fields with the same name, as long as the alias specified with each field is different.

It depends on what you're using to find the usages. If you're using DefineField(), you can press contrl-F12 in vs.net to find all usages of that method in your code.

Frans Bouma | Lead developer LLBLGen Pro
cerberis
User
Posts: 93
Joined: 20-May-2011
# Posted on: 12-Jul-2011 11:16:44   

Otis wrote:

This is not a bug, but a feature (yes), or better: it's a result of a feature: name lookup is more efficient as it's not doing a linear search, but uses an index cache. This has been the case since 2.0.

it can handle fields with the same name, as long as the alias specified with each field is different.

It depends on what you're using to find the usages. If you're using DefineField(), you can press contrl-F12 in vs.net to find all usages of that method in your code.

Thats all what I wanted to know that this is feature simple_smile Thank you for your time.