EF4 + CTP5 + CF:DbContext继承? [英] EF4 + CTP5 + CF: DbContext inheritance?

查看:79
本文介绍了EF4 + CTP5 + CF:DbContext继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分层 DbContext 结构,我想要一个专门的
DbContext 及其拥有
DbSets 继承
DbSets
BaseDbContext


访问基础 ObjectContext with
(( IObjectContextAdapter )this)。 ObjectContext 需要很长时间(几分钟)到
recei是ObjectContext。


是否存在问题 DbContext 在CT5中获得
ObjectContext from derived
DbContext 是不是很有效?


结构是: DbContext(EF4)< - myBaseDbContext< - mySpecializedDbContext


期待任何答案 ... chears& thx。

解决方案


我认为CTP5中的DbContext没有问题,我认为你可以寻找另一个原因。此外,你可以阅读有关如何在CTP5中创建Context对象的信息:


 创建一个上下文


开始使用类进行数据访问的最简单方法是定义一个派生自System.Data.Entity.DbContext的上下文并公开一个类型我模型中每个类的DbSet< TEntity>。


我们现在开始使用CTP5中的类型,因此我们需要添加对CTP5程序集的引用:



  • 项目 - >添加参考…
  • 选择".NET”标签
  • 从列表中选择“ EntityFramework”
  • 点击"确定&rdqu" o;

您还需要对现有实体框架程序集的引用:



  • 项目 - >添加参考…
  • 选择".NET”标签
  • 选择“ System.Data.Entity”从列表中
  • 点击"确定"”

在Program.cs的顶部为System.Data.Entity添加using语句

   使用 System.Data.Entity; 

在我们定义的现有类下面添加派生上下文

   公共类  ProductContext      DbContext 
{
public DbSet < 类别>类别{ get ; set ; }
public DbSet < 产品>产品{获取; set ; }
}

更多信息,请阅读
演练。


感谢


Hi, i have a hierarchical DbContext structure, where i would like a specialized DbContext with its own DbSets to inherit the DbSets of a BaseDbContext.

While accessing the underlying ObjectContext with ((IObjectContextAdapter)this).ObjectContext it takes to long time (several minutes) to receive the ObjectContext.

Is there an issue with DbContext in CT5, that getting an ObjectContext from derived DbContext is not performantly possible?

The structure is: DbContext(EF4) <- myBaseDbContext <- mySpecializedDbContext
Looking forward to any answer...chears & thx.

解决方案

Hi,

I don't think there's an issue with DbContext in CTP5, I think you could look for another reason. Further, you can read this about how to create Context Object in CTP5:

 Create a Context

The simplest way to start using the classes for data access is to define a context that derives from System.Data.Entity.DbContext and exposes a typed DbSet<TEntity> for each class in my model.

We’re now starting to use types from CTP5 so we need to add a reference to the CTP5 assembly:

  • Project -> Add Reference…
  • Select the “.NET” tab
  • Select “EntityFramework” from the list
  • Click “OK”

You’ll also need a reference to the existing Entity Framework assembly:

  • Project -> Add Reference…
  • Select the “.NET” tab
  • Select “System.Data.Entity” from the list
  • Click “OK”

Add a using statement for System.Data.Entity at the top of Program.cs

using System.Data.Entity;

Add a derived context below the existing classes that we’ve defined

public class ProductContext : DbContext
{
  public DbSet<Category> Categories { get; set; }
  public DbSet<Product> Products { get; set; }
}
 

More infomation, read the walkthrough.

thanks


这篇关于EF4 + CTP5 + CF:DbContext继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆