The entity type 'XXX' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'
.NET Core使用EF时 报错如下信息:
The entity type 'XXX' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'
源代码为:
Model.DataModelContext _context = new Model.DataModelContext();
_context.业务方法();
改为如下即可:
using(Model.DataModelContext _context = new Model.DataModelContext())
{
_context.业务方法();
}