My table has two ID fields (I did not put 2 IDs so dont ask me why). One is a primary key and the other is a nullable duplicate field which will contain the value of the primary key itself.
public static void UpdateDuplicate_ID(Company updatingCompany)
{
Company tempCompany;
using (var context = new TestLiveDataContext())
{
tempCompany = (from company in context.Companies
where company.Id == updatingCompany.Id
select company).FirstOrDefault();
tempCompany.DuplicateId = updatingCompany.DuplicateId;
context.SubmitChanges();
}
}
It seems the above code is not working. I can’t update the duplicate id with my primary key value. Can anyone tell me whether I am missing anything here?
As much as I can see,
updatingCompanyandtempCompanyappear to be the same record.If this is the case, you may be overwriting the chance outside of this method if you later change the value passed in and save again.
Does beg the question, why don’t you just change the value in
updatingCompanyand then submit changes on its own context, rather than starting up a new one?That is unless I have misunderstood the problem.