Tuesday, March 6, 2012

LINQ to SQL not updating the record in the table

Hi,

I was using LINQ to SQL (first time to be honest) and i was excited. So one of my task was to update db table for which i used the following code.

MPSCGetDataFromDBDataContext dc = new MPSCGetDataFromDBDataContext();
MPSC_WFStatus wfStatus = dc.MPSC_WFStatus.Single(p => p.WFID == item.WFID);
wfStatus.IsNew = 1;
dc.SubmitChanges();

But it was not updating the data table. So after hitting my head on wall for a while, finally i broke it and found the silly mistake that i made:
---- Define Primary key on dbml.

aha... what a relief.. its updating the tables. Just posting incase any of you are in the same situation.

-Cheers!