public abstract class RepositoryBase<T> : IRepository<T> where T : class
{
private ShopCoreDbContext dbContext;
private readonly DbSet<T> dbSet; //here
protected IDbFactory DbFactory { get; private set; }
protected ShopCoreDbContext DbContext
{
get => dbContext ?? (dbContext = DbFactory.Init());
}
protected RepositoryBase(IDbFactory dbFactory)
{
DbFactory = dbFactory;
dbSet = DbContext.Set<T>();
}
public virtual T Add(T entity)
{
return dbSet.Add(entity); //err here
}
}
Run Code Online (Sandbox Code Playgroud)
使用IDbSet没有任何反应.但实体核心中不再存在IDbSet接口.这是错误细节:
无法隐式将Microsoft.entityframeworkcore.changetracking.entityentry类型转换为T.
它要求它必须是一个接口.
那我现在该怎么办?