У меня есть следующие классы:
public class Customer {
public virtual int Id {get; set;}
public virtual string Surname {get; set;}
public virtual string Prename {get; set;}
public virtual Location Location {get; set;}
}
public class Location {
public virtual int Id {get; set;}
public virtual string ZipCode {get; set;}
public virtual string Name {get; set;}
}
public class CustomLocation : Location {
}
и следующее сопоставление:
public class CustomerMapping : ClassMapping<Customer> {
public CustomerMapping(){
Table("Customer");
Property(a => a.Surname, b =>
{
b.NotNullable(true);
});
Property(a => a.Prename, b =>
{
b.NotNullable(true);
});
ManyToOne(a => a.Location, b =>
{
b.Column($"FK_Location_Id");
});
}}
public class LocationMapping : ClassMapping<Location> {
public LocationMapping(){
Table("Location");
Property(a => a.ZipCode, b =>
{
b.NotNullable(true);
});
Property(a => a.Name, b =>
{
b.NotNullable(true);
});
}}
public class CustomLocationMapping : ClassMapping<CustomLocation>{
public CustomLocationMapping(){
Table("CustomLocation");
Property(a => a.ZipCode, b =>
{
b.NotNullable(true);
});
Property(a => a.Name, b =>
{
b.NotNullable(true);
});
}}
Моя цель состоит в том, чтобы у меня была таблица Location
, которая обновляется автоматическисценарий и таблица CustomLocation
, где пользователь может добавлять местоположения, если они отсутствуют (или за пределами страны).
Моя проблема в том, что я не знаю, как правильно сопоставить это с Customer
, что это может быть как Location
, так и CustomLocation
.
Есть идеи?Заранее спасибо.