.NET Core创建DbContext报错:Cannot create a DbSet for 'XXX' because this type is not included in the model for the context.
System.InvalidOperationException:“Cannot create a DbSet for 'sys_UpgraderSystemName' because this type is not included in the model for the context.”
目录
调用下面代码报错:
C# 全选
public virtual IQueryable<T> GetQueryable<T>() where T : class
{
return this.Set<T>().AsQueryable<T>().AsNoTracking();
}
解决方案
在 OnModelCreating 方法内注册实体模型。
C# 全选
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity(typeof(sys_UpgraderSystemName));
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网