简体   繁体   中英

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. I get this error

"More than one property map found for property 'Id' when using case-insensitive search. "

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:

if the field name contains a suffix of ID (case-insensitive), then EF will automatically include it as a primary key

The table has already a primary key (named '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?

this is how to disable the id convention of EF:

inside OnModelCreating

            modelBuilder.Conventions.Remove<IdKeyDiscoveryConvention>(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM