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?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
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. HoweverDbContext
moving forward would be the preferred way to interact with EF.So how is it different from
ObjectContext
? Well semantically they are exactly same but they reduced lot of extra noise thatObjectContext
had. Like exposing a set required more work, for instance:With
DbContext
you can do: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 onDbContext
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.This means if you are using
ObjectContext
right now, with a little bit of code, you can easily move toDbContext
.It's a bit too late, but for the googlers.
DbContext
is used forEF
(EntityFramework) andDataContext
is used forL2S
(LINQ To SQL).