简体   繁体   English

如何从实体数据模型(edmx)生成数据上下文类?

[英]How to generate data context class from entity data model (edmx)?

This is my first time to use Entity Data Model as data access layer. 这是我第一次使用实体数据模型作为数据访问层。

From some example codes, I see people have data context class that inherit from DbContext 从一些示例代码中,我看到人们拥有从DbContext继承的数据上下文类。

[file name: FooEntities.Context.tt]
public partial class FooEntities : DbContext
{
    // ...
}

when I try to Add Code Generation Item from entity data model (edmx) , I always have data context class that inherit from ObjectContext 当我尝试从实体数据模型(edmx) Add Code Generation Item ,我总是有从ObjectContext继承的数据上下文类

[file name: FooEntities.Context.tt]
public partial class FooEntities : ObjectContext
{
    // ...
}

So, how do we generate data context files that inherits from DbContext ? 那么,我们如何生成从DbContext继承的数据上下文文件?

The DbContext is part of the EF 4.1, unless you are using this specific version or upper (not yet) you will not have this class. DbContext是EF 4.1的一部分,除非您使用的是此特定版本或更高版本(尚未),否则您将没有此类。

More info here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM