我最近通过nuget升级了EF,但现在当我的代码要访问Logs对象集时,它会抛出上面的异常..
错误表明对象设置为Logs and Fulfillment.Model.IUnitOfWork.Logs'都可以包含类型为'Fulfillment.Model.Log'。
的实例我最近在ninject上安装了hangfire,我想知道这是否与它有关?
这是我的datacontext / uow
public interface IUnitOfWork
{
IDbSet<Log> Logs { get; }
IDbSet<Order> Orders { get; }
void Commit();
}
public partial class FulfillmentEntities : DbContext, IUnitOfWork
{
public FulfillmentEntities()
: base("name=FulfillmentEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Log> Logs { get; set; }
public DbSet<Order> Orders { get; set; }
IDbSet<Log> IUnitOfWork.Logs
{
get { return Logs; }
}
void IUnitOfWork.Commit() {
SaveChanges();
}
IDbSet<Order> IUnitOfWork.Orders
{
get { return Orders; }
}
}
}
非常感谢任何建议。
答案 0 :(得分:1)
您有Logs
两次曝光:
public DbSet<Log> Logs { get; set; }
IDbSet<Log> IUnitOfWork.Logs
{
get { return Logs; }
}
(与Orders
相同的问题)
尝试将代码更改为:
public partial class FulfillmentEntities : DbContext, IUnitOfWork
{
public FulfillmentEntities()
: base("name=FulfillmentEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public IDbSet<Log> Logs { get; set; }
public IDbSet<Order> Orders { get; set; }
public void Commit()
{
SaveChanges();
}
}