У меня есть классы моделей:
public partial class InventoryCustomer : EntityBase, ICrudEntity<int>
{
public int Id { get; set; }
public int? SlsalesLevelTypeId { get; set; }
public long? SalesLevelId { get; set; }
public virtual Customer Customer { get; set; }
public virtual GroupOfCustomer GroupOfCustomer { get; set; }
}
public partial class Customer : EntityBase, IPkEntity<long>
{
public long Id { get; set; }
public virtual ICollection<InventoryCustomer> InventoryCustomer { get; set; }
}
public partial class GroupOfCustomer : EntityBase, ICrudEntity<int>
{
public int Id { get; set; }
public virtual ICollection<InventoryCustomer> InventoryCustomer { get; set; }
}
Идентификатор свойства должен оставаться int
в GroupsOfCustomer
и long
в Customer
.
Зависит от SlsalesLevelTypeId, SalesLevelId в InventoryCustomer и ссылается на Customer или GroupOfCustomer.
Класс карты выглядит следующим образом:
public class InventoryCustomerMap : EntityTypeConfiguration<InventoryCustomer>
{
public override void Map(EntityTypeBuilder<InventoryCustomer> builder)
{
builder.ToTable("InventoryCustomers");
builder.HasKey(e => e.Id);
builder.Property(e => e.SalesLevelId).HasColumnName("SalesLevelID");
builder.HasOne(d => d.Customer)
.WithMany(p => p.InventoryCustomer)
.HasForeignKey(d => d.SalesLevelId)
.HasPrincipalKey(p => p.Id);
builder.HasOne(d => d.GroupOfCustomer)
.WithMany(p => p.InventoryCustomer)
.HasForeignKey(d => d.SalesLevelId)
.HasPrincipalKey(p => p.Id);
}
}
Но когда я запускаю код, я получаю ошибка:
![enter image description here](https://i.stack.imgur.com/HRBpX.png)