简体   繁体   中英

linq to sql + update table

Heres a newb question for you.

I have a multi tier environment so i dont have the origional datacontext where the item was created, thus i am having an issue getting the table to update correctly - here is what im doing:

1.) Get the object from the DAL layer 2.) make changes 3.) call update on the DAL layer and pass the modified entity 4.) on the DAL layer where im trying to update:

var a = (p => p.ID == 3);
a = myPassedInEntity
myContext.Update();

if i inspect 'a' prior to calling update it has the values of the myPassedInEntity but saving just saves the old data.

Why is there no UpdateOnSubmit() like there is InsertOnSubmit() ?

There's a couple options to fix your problems here - see the answers to this question or this one for more info. Basically your options are to use the Linq serialization so that it can cross DataContext boundaries, use a timestamp to track row versions, or update your properties one by one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM