Entity Framework 4.3 Basics for Entity Framework 5 Display Exception

I am migrating a project from Entity Framework 4.3 running on .net 4 to Entity Framework 5 running on .net 4.5. Without making any changes, when I try to start a project, with a code model configuration error using System.Data.MappingException , a message appears:

(495,10): error 3034: problem with displaying fragments starting from lines 495, 536: two objects with different keys are displayed on the same line. Make sure that these two display fragments do not display two groups of objects with different keys in the same group of rows.

[deleted 5 other similar paragraphs]

The message does not indicate which entity or attitude is causing the problem, and my model is quite complex. Is there a way that I can get more useful information to make it easier to diagnose the problem?

+4
source share
1 answer
Ladislav was right to propose the problem of inheritance. It seems that Entity Framework 4.3 and Entity Framework 5 behave a little differently when it comes to code scenarios “Table configuration to hierarchy”.

In this case, I had four derived types, each of which had its own configuration class derived from EntityTypeConfiguration<T> . The underlying abstract type did not have a configuration registered in the model builder. This is not a problem in EF 4.3, which simply created a table named after the base type with the Discriminator column to distinguish between the types.

To get the same behavior with EF 5, you had to create an empty configuration class

 public class MyBaseConfiguration : EntityTypeConfiguration<MyBase> { // Nothing happening here } 

and then register it using the model builder

 public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new MyBaseConfiguration()); // Add configurations for derived and other types as normal } } 
+4
source

All Articles