I'm trying to determine what EF6 is telling me, and it's not making much sense to me, so I'm hoping someone here can clarify this.
I'm setting up my FluentApi as so (composite keys in use in the DB, this is Code First from Database):
modelBuilder.Entity<Object1>()
.HasKey(e => new { e.Property1, e.Property2 }
.HasMany(e => e.Object2s)
.WithRequired(e => e.Object1)
.HasForeignKey(e => new { e.Property1, e.Property2 });
modelBuilder.Entity<Object2>()
.HasKey(e => new { e.Property2, e.Property3, e.Property1 })
.HasRequired(e => e.Object1)
.WithMany(e => e.Object2s)
.HasForeignKey(e => new { e.Property1, e.Property2 });
All builds fine, but when I go to select anything, I get this:
"Foreign key constraint 'Object1_Object2' from table Object2 (Property2, Property1) to table Object1 (Property1, Property2):: Insufficient mapping: Foreign key must be mapped to some AssociationSet or EntitySets participating in a foreign key association on the conceptual side."
Ideas? I don't understand why the FK constraint is showing Object2's FK in the incorrect order, when I've defined the correct order in the FluentApi.
Object2's key is defined as 3 properties, but onObject1, you only have 2 properties in theHasForeignKeyclause - Eris