如何将ObjectSet转换为DbSet

时间:2015-03-25 19:24:27

标签: c# entity-framework

我正在尝试从抽象类创建类:

public class ManufacturerEntityService : BaseEntityService<Manufacturer>
{
    Entities entities = new Entities();

    protected override ObjectSet<Manufacturer> EntitySet
    {
        get { return entities.Manufacturers; }
    }

}

发生错误:

  

无法隐式转换类型System.Data.Entity.DbSet&lt; _21century.Models.Manufacturer&gt;&#39; to&#39; System.Data.Objects.ObjectSet&lt; _21century.Models.Manufacturer&gt;&#39;

在BaseEntityService中我使用了ObjectSet,导致DbSet没有SaveData方法。问题是如何将ObjectSet转换为DbSet?有可能吗?有没有走路?我必须在那里传递DbContext obj吗?

我是创建mvc项目的新手。搜索没有给出任何结果。希望有人可以帮助我。

1 个答案:

答案 0 :(得分:0)

答案可以在这里找到:How to convert DbSet in Entity framework to ObjectQuery

public class ManufacturerEntityService : BaseEntityService<Manufacturer>
{
    Entities entities = new Entities();

    protected override ObjectSet<Manufacturer> EntitySet
    {
        get 
        { 
            ObjectContext objectContext = entities.ObjectContext;  
            return objectContext.CreateObjectSet<Manufacturer>("Manufacturers");
        }
    }

}