简体   繁体   中英

Entity Framework Core - Debugging Mapping

I have an existing database and an existing domain, it was originally created and accessed using nHibernate and am now moving it to Entity Framework Core.

I've started by trying to access just one element of the domain (which is unfortunately tightly-coupled with a lot of other entities). The domain is very legacy and monolithic and can NOT be modified as part of this exercise.

I get a lot of errors similar to: "The property 'DateTimeFormatInfo.AbbreviatedDayNames' could not be mapped, because it is of type 'String[]' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'."

.NET type mapping aside, it's very difficult to try and figure where exactly the mapping is failing. Is there a tool or way of easily identifying the failing section.

I have tried the following: - SQL Trace, nothing as it fails in the app. - Exception just gives that error, no inner exception or further information. - Did a text search in the entire solution for entities with elements of type of 'DateTimeFormatInfo'. There are none. - Did a text search in entire solution for entities including or using property/function AbbreviatedDayNames, also nothing.

I'm therefore stuck trying to locate exactly which entity mapping is failing.

Additionally I'm eager to use the EF Fluent API for any mapping.

You have be searching for the wrong text.
DateTimeFormatInfo.AbbreviatedDayNames is not a Property. You should instead try find any Properties with type 'String[]', so search for that in Entites.
And the error itself says where the problem is. EF can't map array of string to any db type.

I experienced the exact same error as above migrating an application to Entity Framework core as well just now

The property 'DateTimeFormatInfo.AbbreviatedDayNames' could not be mapped, because it is of type 'String[]' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'."

In my case the issue was related to an entity with a CultureInfo property Type.

System.Globalization.CultureInfo.DateTimeFormat is a DateTimeFormatInfo type and is the Property the error was describing in my case.

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