从模型中删除冗余
本文关键字:冗余 删除 模型 | 更新日期: 2023-09-27 18:28:23
我必须为商店和商场的概念建模。商场内可能包含商店,也可能不包含商店。如果一个商店包含在一个购物中心内,它应该与父购物中心共享相同的地址/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; }
}
我如何才能最好地构建它,这样我就不会在商店对象中再次保存商场的地址?
试试这个:
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; }
}