yourContext.Configuration不可用

时间:2014-04-02 01:40:09

标签: c# entity-framework-5

在之前的帖子中,我读到了关于设置的内容:

yourContext.Configuration.AutoDetectChangesEnabled = false;
yourContext.Configuration.ValidateOnSaveEnabled = false;

提高批量插入性能。我正在使用Entity Framework 5.0,但无法找到yourContext.Configuration对象。当我选择上下文时,我只看到ContextOptions,而不是配置。我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

使用上下文的推荐方法是定义一个派生自DbContext的类。 它是您数据库的摘要。并公开表示上下文中指定实体集合的DbSet属性。

例如:

using System.Data.Entity;

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

然后你可以这样做

using (var context = new ProductContext())
{
     context.Configuration.AutoDetectChangesEnabled = false;
}
相关问题