我必须模拟商店和商场的概念。商店可能包含也可能不包含商店。如果商店包含在商场中,它应该与父商城共享相同的地址/ GeoMarket属性。但是,我还需要保存商店号码'在Address_Line1(或其他)中的商店,但其他属性将保持不变。
public class Store
{
public int StoreId { get; set; }
public string Name { get; set; }
public string Address_Line1 { get; set; }
public string Address_Line2 { get; set; }
public string City { get; set; }
public string Zipcode { get; set; }
public virtual GeoMarket Market { get; set; }
public virtual Mall Mall { get;set; }
}
public class Mall
{
public int MallId { get; set; }
public string Name { get; set; }
public string Address_Line1 { get; set; }
public string Address_Line2 { get; set; }
public string City { get; set; }
public string Zipcode { get; set; }
public virtual GeoMarket Market { get; set; }
}
我如何才能最好地构建这个,以便我不会再在商店对象中保存商城的地址?
答案 0 :(得分:0)
试试这个:
class Store
{
public int StoreId { get; set; }
public string Name { get; set; }
public int? MallId { get; set; }
public virtual GeoMarket Market { get; set; }
public virtual Mall Mall { get; set; }
}
class StandAloneStore : Store
{
public Address Address { get; set; }
}
class Address
{
public string Address_Line1 { get; set; }
public string Address_Line2 { get; set; }
public string City { get; set; }
public string Zipcode { get; set; }
}
class Mall
{
public int MallId { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
public virtual GeoMarket Market { get; set; }
IList<Store> Stores { get; set; }
}