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.业务方法();

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM