This project is read-only.

Argument Exception thrown - An item with the same key has already been added

Jul 30, 2012 at 10:41 PM
Edited Jul 31, 2012 at 3:29 PM

I have created a brand new project in VS2010 with 3 entities and an associative table.  2 entities are related through the associative table.

However I have hit a problem when calling any entity code.  I get a Argument Exception with the message "An item with the same key has already been added".

The following entities have been created using the designer: 


ID [Int] Not Null - PK
Field 1 [VarChar] (50) Not Null


ID [Int] Not Null - PK
Field 1 [VarChar] (50) Not Null


ID [Int] Not Null - PK
Field 1 [VarChar] (50) Null


e1 [Int] Not Null
e2 [Int] Not Null


Entity1.ID -> EntityAssociation.e1
Entity2.ID -> EntityAssociation.e2

NOTE: Entity3 is it's own standalone entity with no relationships.

EntityAssociation is my Associative table (green in the designer).

When I start the program (simple WinForm in C#) I call the following code in Form Load:

var x = new XXX.YYY.EFDAL.YYYEntities(@"Data Source=.\SQL2008;Initial Catalog=XXXYYY;Integrated Security=True");

var zz = x.Entity3.ToList();

 The ArgumentException exception occurs on the line:

this._entity3 = base.CreateObjectSet<XXX.YYY.EFDAL.Entity.Entity3>("Entity3");

in the property get for Entity3 in YYYEntities.Generated.cs.

Am I doing something wrong? Any thoughts?

I am desparate in need of a fix/workaround/any help for this.  I've added this as an issue now.