我有一个使用FK ProductId有关系的实体,然后我使用复合键ProductId和VehicleId在同一个实体上有另一个关系。这不起作用。我得到了
在模型生成期间检测到一个或多个验证错误:
ProductId:Name:类型中的每个属性名称必须是唯一的。属性 name' ProductId'已定义。
配置代码
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");
});
}
}