C# 为什么我的数据库上下文中不存在 ObjectStateManager 属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13581473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does the ObjectStateManager property not exist in my db context?
提问by Kenci
I need to return a list of newly added objects from my database context.
我需要从我的数据库上下文中返回一个新添加的对象列表。
I have read that i have to use ObjectStateManagerfor this purpos. The problem is, that my database context does not have the ObjectStateManagerproperty.
我已经读到我必须为此目的使用ObjectStateManager。问题是,我的数据库上下文没有该ObjectStateManager属性。
The context works fine for retrivieing, adding and updating objects though.
不过,上下文对于检索、添加和更新对象来说效果很好。
I am using EF 5.0
我正在使用 EF 5.0
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
What can i do?
我能做什么?
采纳答案by Hamlet Hakobyan
Try this:
尝试这个:
var manager = ((IObjectContextAdapter)dbContext).ObjectContext.ObjectStateManager;
回答by Yared T G
Try this:
尝试这个:
dbContext.Entry(entity).State = EntityState.Modified;

