Linq/Entity Framework 中的对象和上下文有什么区别
从数据库自动生成的代码的实体对象和实体上下文有什么区别?
What's the difference between entity object and entity context for auto generated code from database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否正确理解了你的问题。
实体对象是映射到数据库表的实体类的实例(如果它们是自动生成的)。
对象上下文(这是您的意思吗?有时也称为实体上下文)是 EDM(实体数据模型)的中心类,您可以使用它查询和更新数据库中存储的数据。默认情况下,它也是自动生成的。
如果这不是您想要的,请提供更多详细信息或更具体的问题。
I am not sure I get your question correctly.
Entity Objects are the instances of the entity classes which are mapped to the tables of your database (if they are generated automatically).
The Object Context (is this what you meant? it is sometimes called entity context as well) is the central class of your EDM (Entity Data Model) with which you query and update the data stored in the DB. By default, it is automatically generated too.
If this is not what you are looking for, please provide more details or be more specific in the question.
Fad,
在基于 EF 的应用程序中,上下文负责跟踪从数据库加载实体后对实体所做的更改。然后,您可以在上下文中使用 SaveChanges 方法将更改保存回数据库
希望这能让您了解上下文是什么。
Fad,
In an EF-based application a context is responsible for tracking changes that are made to the entities after they have been loaded from the database. You then use the SaveChanges method on the context to persist the changes back to the database
Hope that gave you some idea what context is.