我试图绕过使用我在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();
}
//....
}