我必须对商店和购物中心的概念进行建模。商店可能包含在商场内,也可能不包含在商场内。如果商店包含在商城中,它应该与父商城共享相同的地址/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; }
}
我如何才能最好地组织它,这样我就不会在store对象中再次保存商场的地址了?
发布于 2014-10-30 23:28:42
试试这个:
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; }
}
https://stackoverflow.com/questions/26656644
复制相似问题