I am hitting ModelValidationException when I use CodeFirst/DbModelBuilder to build my data model. One of my entities has DbGeography property. As long as I run the app, I will get the below exception:
One or more validation errors were detected during model generation:
\thttp://schemas.microsoft.com/ado/2009/11/edm.DbGeography: : EntityType 'DbGeography' has no key defined. Define the key for this EntityType.
I tried EF 5 and EF 6 apha1 and had the same issue.
Comments: Thanks for reporting this issue. I was able to get the exception by configuring Code First to produce a model with an old EDM version that doesn't support spatial types and at the same time consider DbGeography as a candidate entity type. Doing this two things does not make much sense so we need a repro that triggers the issue in a real-world scenario. Here is my repro code: [DbModelBuilderVersion(DbModelBuilderVersion.V4_1)] public class MyContext: DbContext { public DbSet<Location> Locations { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<DbGeography>(); } } public class Location { public int Id { get; set; } public string Name { get; set; } public DbGeography Point { get; set; } }
One or more validation errors were detected during model generation:
\thttp://schemas.microsoft.com/ado/2009/11/edm.DbGeography: : EntityType 'DbGeography' has no key defined. Define the key for this EntityType.
I tried EF 5 and EF 6 apha1 and had the same issue.
Comments: Thanks for reporting this issue. I was able to get the exception by configuring Code First to produce a model with an old EDM version that doesn't support spatial types and at the same time consider DbGeography as a candidate entity type. Doing this two things does not make much sense so we need a repro that triggers the issue in a real-world scenario. Here is my repro code: [DbModelBuilderVersion(DbModelBuilderVersion.V4_1)] public class MyContext: DbContext { public DbSet<Location> Locations { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<DbGeography>(); } } public class Location { public int Id { get; set; } public string Name { get; set; } public DbGeography Point { get; set; } }