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方法里加上这个
然后就没有报错了,具体咋回事菜菜的我也不太懂,回头详细了解一下,反正人和代码,有一个能跑就行了😏