Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 11, 2011 05:37 AM by gperchenko
Member
78 Points
56 Posts
Apr 11, 2011 05:37 AM|LINK
I have a simple 2 table relationship:
table 'a' contains FK to table 'b'. Table b contains a fixed number of records. A record in table 'a' over time need to point to different
records in table 'b'. I understand that in linq I cannot just chenge FK, I need to change the entity that it represents. So I do
a.b_entity = db.bs.single(b => b.id == <other id> );
<other_id> exists in database. It works exept for one minor thing, For some reason, LINQ replicated record in table b and assigns the id
of the new record. I do not need to create a new record! I need Fk in 'a' to piont directly to the record I selected in b and not its copy.
What am I doing wrong?
gperchenko
Member
78 Points
56 Posts
Updating foregn Key in Linq to sql
Apr 11, 2011 05:37 AM|LINK
I have a simple 2 table relationship:
table 'a' contains FK to table 'b'. Table b contains a fixed number of records. A record in table 'a' over time need to point to different
records in table 'b'. I understand that in linq I cannot just chenge FK, I need to change the entity that it represents. So I do
a.b_entity = db.bs.single(b => b.id == <other id> );
<other_id> exists in database. It works exept for one minor thing, For some reason, LINQ replicated record in table b and assigns the id
of the new record. I do not need to create a new record! I need Fk in 'a' to piont directly to the record I selected in b and not its copy.
What am I doing wrong?