是DbContext与DataContext相同吗? [英] Is DbContext the same as DataContext?
问题描述
我正在追踪 Scott Gu 引用一个名为DbContext的类。我不能在框架4上的任何命名空间找到它,它似乎在我被重命名从CT4 DbContext到.net4 System.Data.Linq.DataContext。我的假设是否正确?
I'm following a tutorial by Scott Gu that refers to a class named DbContext. I can't find it on any namespace on framework 4 and it seems to me it was renamed from CT4 DbContext to .net4 System.Data.Linq.DataContext. Is my assumption correct?
推荐答案
DbContext
添加在最近由EF团队单独下载。它目前不是核心EF 4.0的一部分。 DbContext
前进是与EF交互的首选方式。
DbContext
is a new class that was added in the recent separate download by EF team. It is currently not part of the core EF 4.0. However DbContext
moving forward would be the preferred way to interact with EF.
c $ c> ObjectContext ?在语义上他们是完全相同的,但他们减少了大量的额外的噪音, ObjectContext
有。像暴露一个集需要更多的工作,例如:
So how is it different from ObjectContext
? Well semantically they are exactly same but they reduced lot of extra noise that ObjectContext
had. Like exposing a set required more work, for instance:
public ObjectSet<Customer> Customers
{
get { return db.CreateObjectSet<Customer>(); }
}
使用 DbContext
您可以:
public DbSet<Customer> Customers { get; set; }
基本上在 ObjectContext
do dot(。
),一切就在那里,这使得列表相当巨大。 EF团队实际想要在 DbContext
上公开的实体是仅特定于您的域的实体,并且框架的其余能力被包含在不同的属性中。
Basically on the ObjectContext
, when you do dot (.
), everything is just right there which makes the list pretty huge. What the EF team actually wanted to expose on DbContext
are entities which are only specific to your domain and rest of ability of the framework is tucked in under different properties. It just makes the programming experience easier.
这意味着如果你现在使用 ObjectContext
的代码,你可以轻松地移动到 DbContext
。
This means if you are using ObjectContext
right now, with a little bit of code, you can easily move to DbContext
.
这篇关于是DbContext与DataContext相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!