开发者

DataContext SubmitChanges in LINQ

开发者 https://www.devze.com 2023-01-08 16:59 出处:网络
Is it safe to call SubmitChanges() when you are not sure whether the data ha开发者_C百科s changed? What does it actually do?It\'s safe, but you should do some testing yourself.I always set the .Log pr

Is it safe to call SubmitChanges() when you are not sure whether the data ha开发者_C百科s changed? What does it actually do?


It's safe, but you should do some testing yourself. I always set the .Log property on my DataContext to log to the debug window. You may discover that you're doing updates you didn't intend to because the data has changed in a way you didn't expect. It's always good to watch what SQL is being generated and how many database calls are happening.


Yeah, its fine, you just won't have anything happening but it won't hurt anything. It basically converts your changes into appropriate SQL and executes the commands against the database.


Yes this is safe. Essentially, LINQ->SQL will examine the set of tracked objects for changes. If any changes were detected it will begin a transaction and apply the changes. If there were no changes, it will do nothing.

See this MSDN article for the order of operations for SubmitChanges.

Remember, the method is called SubmitChanges - meaning that it will only submit changes that have been made to the entity.

0

精彩评论

暂无评论...
验证码 换一张
取 消