【发布时间】:2012-03-29 18:26:57
【问题描述】:
我想创建一个在我的 MVC3 应用程序中使用的数据结构。该网站保存用户上传的视频,我希望能够为视频设置一个位置,以便以后您可以根据国家、地区或城市进行搜索。
这些实体的建模对我来说不是什么大问题,我的问题是我应该为我的视频实体使用哪个类属性。
public class Country
{
int CountryId
string CountryName
}
public class Region
{
int RegionId
string RegionName
int FK_CountryId
}
public class City
{
int CityId
string CityName
int FK_CountryId
int FK_RegionId
}
........
public class Video
{
int VideoId;
string VideoName;
**Location VideoLocation;**
}
**public class Location
{
int LocationId;
Country CountrId;
Region RegionId;
City CityId;
}**
我最初的想法,但我认为这不是一个很好的设计,因为一个位置可以有 2 行相同的行,在其中保留对位置的唯一引用应该是理想的
您认为好的设计和性能如何?
【问题讨论】:
-
我会做
Country VideoLocation;位置重复是你已经拥有的。 -
如果我做 Country VideoLocation 我如何按城市查询?
-
select * from Video where Video.VideoLocation.CountryId = selectedCity.FK_CountryId -
如果我做 Country VideoLocation 我如何按 city 查询?
-
我是怎么写的。或者您问如何按城市名称编写查询?
标签: c# .net database data-modeling