【发布时间】:2014-04-09 05:46:08
【问题描述】:
我正在使用 EF 5、Web Api 和 MVC4 我需要有关此数据库设计的帮助。我需要在数据库中保存医院的城市和城镇,但是没有循环,医院有一个城镇,一个城市有很多城镇
public class City
{
public int CityId { get; set; }
public List<Town> Towns { get; set; }
public string Name { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
public City()
{
Towns = new List<Town>();
}
}
public class Town
{
public int TownId { get; set; }
public int CityId { get; set; }
public string Name { get; set; }
public byte[] RowVersion { get; set; }
}
public class Hospital
{
public int HospitalId { get; set; }
[Required]
public string Name { get; set; }
public int TownId { get; set; }
public Town Town { get; set; }
public int CityId { get; set; }
public City City { get; set; }
public bool IsAvailable { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
public Hospital()
{
this.IsAvailable = true;
}
}
我不喜欢医院类的City属性,但我需要另一种选择,就像一个循环
【问题讨论】:
-
这是否是正确的关系:医院位于一个且只有一个城镇,城镇可能有零个或多个医院,城镇位于一个且只有一个城市,城市有一个或多个城镇。那么,了解城镇意味着您基于这种关系了解这座城市。
标签: c# asp.net-mvc-4 ef-code-first relational-database