.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.業務方法();
}