实体框架4.1 objectContext vs dbContext [英] entity framework 4.1 objectContext vs dbContext
问题描述
可能重复:
ADO.NET DbContext Generator vs. ADO.NET Poco Entity Generator(ObjectContext)
我应该使用ObjectContext还是DbContext?什么是最好的方法?
Should I use ObjectContext or DbContext? What's the best way?
推荐答案
我目前在数据库中使用DbContext第一种情况,它工作正常。 DbContext不仅仅用于代码开发。
I am currently using DbContext in a Database first situation and it is working fine. DbContext is NOT only for Code First development.
DbContext像ObjectContext一样包装。 Julie Lerman有一个很好的解释,你可以如何访问DbContext内的ObjectContext 这里。所以如果你决定使用DbContext,你仍然可以使用ObjectContext解决问题。
DbContext acts like a wrapper around the ObjectContext. Julie Lerman has a nice explanation, how you can access the ObjectContext that is inside of DbContext here. So if you decide to use DbContext, you can still solve things with ObjectContext if you need to.
DbContext简化了常见任务。一个例子是Find()方法。
DbContext simplifies common tasks. One example is the Find() method.
Product p = db.Products.Find(id);
这篇关于实体框架4.1 objectContext vs dbContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!