Reputation: 745
I have recently upgraded EF via nuget but now when my code is going to access the Logs object set it throws the exception above..
The error states that the object set Logs and Fulfillment.Model.IUnitOfWork.Logs' can both contain instances of type 'Fulfillment.Model.Log'.
I recently installed hangfire with ninject and am wondering if that had something to do with it?
Here is my 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; }
}
}
}
Any advice would be greatly appreciated.
Upvotes: 0
Views: 583
Reputation: 38529
You have Logs
being exposed twice:
public DbSet<Log> Logs { get; set; }
IDbSet<Log> IUnitOfWork.Logs
{
get { return Logs; }
}
(and same issue with Orders
)
Try changing your code to:
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();
}
}
Upvotes: 2