I have the following classes:
public class item
{
public int NodeID
{
get ;
set ;
}
public int Weight
{
get ;
set ;
}
public int Category
{
get ;
set ;
}
}
public class Recipients
{
public int RecipientID
{
get ; set;
}
}
public class Nodes
{
public List<int> RecipientList
{
get ;
set ;
}
public item Item
{
get ; set;
}
public int Capacity
{
get ; set;
}
public int NodeID
{
get ; set;
}
public int Weight
{
get ; set;
}
public int Category
{
get ; set;
}
}
And I tried to save it in my existing DB that has the following tables:
1) Category
2) Items
3) Nodes (Node and Items has 1-1 relationship)
4) Recipients
5) NodeRecipients (This table show the many to many relationship between Nodes and Recipients)
I use VS2012 to create an EF model as illustrated by the diagram below (please note that Nodes derives from Items in the EF)

I have a method that tries to save the nodes and its recipients
public void SaveNodeAndRecipient(List<Nodes> MyNodes)
{
using (var db = new MyEntities())
{
foreach (var n in MyNodes)
{
Node n1 = new Node() { NodeID = n.NodeID, categoryID = n.Category, Capacity = n.Capacity };
db.Items.Add(n1);
foreach (var r in n.RecipientList)
{
Recipient rep;
if (!db.Recipients.Select(x => x.recipientID).Contains(r))
{
rep = new Recipient() { recipientID = r };
db.Recipients.Add(rep);
}
else
{
rep = db.Recipients.Where(x => x.recipientID == r).FirstOrDefault();
}
Node_Recipient nr = new Node_Recipient(){RecipientID=r,NodeID=n.NodeID};
n1.Node_Recipient.Add(nr);
}
}
db.SaveChanges();
}
}
MyEntities is the EF model and was declared in the appconfig:
<connectionStrings>
<add name="MyEntities" connectionString="xxxxx" providerName="System.Data.EntityClient" />
</connectionStrings>
Everything was fine and compiled with no problem until I tried to savechanges. I got this error (not very descriptive)

Anyone knows what is going on? I am under the impression that the many to many relationship is the culprit but can not pin point what is causing it. Please help!