System.InvalidOperationException:“The entity type 'XXXXX' has multiple properties with the [Key] attribute. Composite primary keys can only be set using 'HasKey' in 'OnModelCreating'.”

一、前言

当我使用efcore code first成功生成实体类,然后编写好功能,运行的时候

报了这个错误

System.InvalidOperationException:“The entity type 'Student' has multiple properties with the [Key] attribute. Composite primary keys can only be set using 'HasKey' in 'OnModelCreating'.”

 

二、解决

首先百度、谷歌

找到解决方法

然后我按照他说的,删除类里面的特性[Key]

然后在OnModelCreating方法里加上这个

 

然后就没有报错了,具体咋回事菜菜的我也不太懂,回头详细了解一下,反正人和代码,有一个能跑就行了😏

作者:WangJianqiu

出处:https://www.cnblogs.com/WangJianqiu/p/17388567.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   六弦汤姆  阅读(339)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示