数据库:数据库中有三个表,其中 ID 为 int,Codes 为string
datatype
。例外(countryId 也是字符串)。
- 国家(国家 ID,国家代码...)
- 公司(公司 ID、国家 ID、年份、公司代码...)
- 中心(centerId,companyId,年份,centerCode...)
我正在尝试获得两个特定的中心,它们属于我知道中心代码的两个不同国家。
用户操作:用户从国家中选择一个选项(特殊),这是一个额外的同上,添加到给出随机值(即 CORP)的位置。 DropDownList
ListItem
_DropDownListCountry.Items.Insert(1, new ListItem("Special", "CORP"));
预期当用户从 _DropDownListCountry 为特定年份选择上述选项时,应在另一个DropDownList
(_DropDownListCenter) 中填充两个项目。该项目应(例如 1111 和 2222)在列表中。按年与中心和公司有关系。
问题:结果显示为 (1111, 2222, 2222),因为数据库中有两个中心,但年份不同。当我||
在LINQ
查询中使用时会发生这种情况。但我不明白(代码明智)为什么会发生。任何帮助将非常感激。
代码
public static IEnumerable<Center> RetriveCenterssByYear(short year)
{
List<Center> centers;
using (var context = new crEntities())
{
centers = (from pc in context.Centers
join company in context.Companies on pc.CompanyID equals company.CompanyID
join co in context.Countries on company.CountryID equals co.CountryID
where pc.Year == year
&& pc.CompanyID == company.CompanyID
&& company.CountryID.Equals(co.CountryID)
&& pc.centerCode.Contains("1111")
|| pc.centerCode.Contains("2222")
select pc).ToList();
}
return centers;
}