Property Name 'ProductId' Already Defined

I have an entity that relates using the FK ProductId, then I have a different relationship to the same object using the composite keys ProductId and VehicleId. This does not work. I get

During model generation, one or more validation errors were detected:

ProductId: Name: each property name in the type must be unique. The property name 'ProductId' is already defined.

Configuration code

public class BookingConfiguration : EntityTypeConfiguration<Booking> { public BookingConfiguration() { ... HasRequired(b => b.Product) .WithMany(p => p.Bookings) .Map(m => { m.MapKey("ProductId"); }); HasRequired(b => b.Vehicle) .WithMany(v => v.Bookings) .Map(m => { m.MapKey("ProductId","VehicleId"); }); } } 
+5
source share
1 answer
Steve Green set me on the right track, I added ProductId and VehicleId to Entity and used
 HasRequired(b => b.Vehicle) .WithMany() .HasForeignKey(b => new {b.ProductId, b.VehicleId}); 

In the domain perspective, I don't like adding foreign keys to an object, so if someone has a better solution, let me know.

+3
source

All Articles