Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linq2Sql Update Problem

Status
Not open for further replies.

Tibyan

Programmer
Joined
Aug 29, 2008
Messages
2
Location
BA
So I have a problem with updating values in database using linq.

I mapped my database using linq to sql, and there are two tables which are linked to eachother by one to many relation. So in my code if I want to change the foreign key value in child table and SubmitChanges(), I get the ForeignKeyReferenceAlreadyHasValueException.
I also tried to assign the whole (existing) object of the parent table class to the property created by linq in child table class, but in this case, new rows in parent table are inserted instead of updating the foreign key in child table.

How can I handle this error, can someone help?

Thx!
 
Can you post your code please?

 
It's ok, I solved the problem.

I used different DataContext objects, and that's why it treated the object as new object, and couldnt recognize that it already exists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top