开发者

refreshing a collection after a save to db

开发者 https://www.devze.com 2023-04-04 10:50 出处:网络
I save an item to the database, which in turn causes a side-effect which effects a collection I\'ve already obtained from the ObjectContext.

I save an item to the database, which in turn causes a side-effect which effects a collection I've already obtained from the ObjectContext.

I simply want the collection to be refreshed. (Kind of like doing ObjectContext.Refresh -- but for a colle开发者_运维问答ction of items). Iterating over the collection is not an option -- there may have been items added or removed in the database.

How can I accomplish this?


In such case you must execute query to populate the collection again. Moreover you must correctly configure its MergeOption.

context.Things.MergeOption = MergeOption.OverwriteChagnes;
var myThings = context.Things.Where(t => t.IsFat);

EF and other ORMs don't like side effects in database.

0

精彩评论

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