实体类型Interests不是当前上下文的模型的一部分

时间:2016-08-15 22:10:14

标签: c# entity-framework

我试图绕过使用我在Dbcontext / Dbset实体框架中使用的相同模型

原因是我试图进入自动播放器,但在此之前,我认为由于我的主要核心属性存在,我应该能够使用业务poco而不是数据访问poco

IGenericRepository<Data.BusinessEntities.Interests> interestRepository = null;
interestRepository = new GenericRepository<Interests>();
var interest = interestRepository.SelectAll().ToList();

这会爆发

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Additional information: The entity type Interests is not part of the model for the current context.

public class GenericRepository<T> : IGenericRepository<T> where T : class
{
    //private GenericRepoContext db = null;
    private readonly InternTrackingDbContext db;
    private DbSet<T> table = null;

    public GenericRepository()
    {
        //this.db = new GenericRepoContext();
        this.db = new InternTrackingDbContext();
        table = db.Set<T>();
    }

    //public GenericRepository(GenericRepoContext db)
    public GenericRepository(InternTrackingDbContext db)
    {
        this.db = db;
        table = db.Set<T>();
    } 

    public IEnumerable<T> SelectAll()
    {
        return table.ToList();
    }

 //....
}

0 个答案:

没有答案