[英]Entity Framework primary key convention. How to allow more columns with 'id' in their name?
I am developing a web app on an existing database which unfortunately I cannot change. 我正在现有数据库上开发Web应用程序,很遗憾,我无法更改。 I get this error 我得到这个错误
"More than one property map found for property 'Id' when using case-insensitive search. " “使用不区分大小写的搜索时,为属性'Id'找到了多个属性映射。”
After a little search I found that the problem is that there are some conventions in EF and more specifically one that states (according to what I read here ) that: 经过一番搜索后,我发现问题在于EF中有一些约定,更具体地讲(根据我在此处的阅读内容)指出:
if the field name contains a suffix of ID (case-insensitive), then EF will automatically include it as a primary key 如果字段名称包含ID后缀(不区分大小写),则EF会自动将其作为主键
The table has already a primary key (named 'id'). 该表已经有一个主键(名为“ id”)。 Is there a way to disable the EF conventions or in any other way to allow having besides my 'id' field, a field named "something_id" without getting this error? 有没有一种方法可以禁用EF约定或以其他任何方式允许除我的“ id”字段外,还有一个名为“ something_id”的字段而不会出现此错误?
this is how to disable the id convention of EF: 这是如何禁用EF的id约定:
inside OnModelCreating 在OnModelCreating内部
modelBuilder.Conventions.Remove<IdKeyDiscoveryConvention>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.