It is a compound key in the StoreItemModifierAssignments table, automatically generated by EF when I add a StoreItemModifier to a StoreItem.
The problem is that when I try to assign new StoreItemModifiers to an existing StoreItem, EF tries to insert new entries, even if the records already exist. I'm sure it is being caused by an error on my part, I just don't know what I'm doing wrong
Not sure what the etiquette here is... but I have uploaded a sample as a zip file for VS2010
https://docs.google.com/file/d/0B8K2sK89O60SdGt2TGp4dTRreVU/edit
The first time it runs, it adds and updates the modifiers properly. If you run it a second time, it crashes with PK violations
mgasparel
Member
298 Points
65 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 12:59 AM|LINK
No, there must be something wrong with the way I am using EF, but I don't know what
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 01:06 AM|LINK
Your primary key is generated or manually assigned?
mgasparel
Member
298 Points
65 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 01:12 AM|LINK
It is a compound key in the StoreItemModifierAssignments table, automatically generated by EF when I add a StoreItemModifier to a StoreItem.
The problem is that when I try to assign new StoreItemModifiers to an existing StoreItem, EF tries to insert new entries, even if the records already exist. I'm sure it is being caused by an error on my part, I just don't know what I'm doing wrong
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 05:22 AM|LINK
Well……Maybe you need to submit your proj in the form of Console App to re-produce your issue.
Reguards!
mgasparel
Member
298 Points
65 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 06:56 AM|LINK
Not sure what the etiquette here is... but I have uploaded a sample as a zip file for VS2010
https://docs.google.com/file/d/0B8K2sK89O60SdGt2TGp4dTRreVU/edit
The first time it runs, it adds and updates the modifiers properly. If you run it a second time, it crashes with PK violations
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 06:59 AM|LINK
Can you merge all the files into one zip?
mgasparel
Member
298 Points
65 Posts
Re: Removing records from a one to zero or many relationship
Jan 25, 2013 02:46 PM|LINK
There's a File menu at the top of the page, with an option to download the whole zip
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing records from a one to zero or many relationship
Jan 26, 2013 02:25 AM|LINK
Hi again,
I'll call a senior person to work with you about your complicated problem.
sachinp290
Member
88 Points
21 Posts
Re: Removing records from a one to zero or many relationship
Jan 27, 2013 08:01 AM|LINK
you might be fetching edit object from another context than context you are saving. Linq strictly works on context base. please try below code
public void save( Item item)
{
DatabaseDataContext db = new DatabaseDataContext();
var dbitem = db.Items.firstOrDefault(x=>x.ID==item.ID);
dbitem.Name = item.Name;
dbitem.Address = item.Address;
db.submitChanges();
}
This approch will work for you. your problem was you are trying to save object which is not in the current context.
}