开发者

refreshing a collection after a save to db

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜