データベース:データベースには、IDがintでコードが。の3つのテーブルがありますstring
datatype
。例外的です(countryIdも文字列です)。
- 国(countryId、countryCode ...)
- Company(companyId、countryId、year、companyCode ...)
- Center(centerId、companyId、year、centerCode ...)
センターのコードを知っている2つの異なる国に属する2つの特定のセンターを取得しようとしています。
User Action :ユーザーは、ランダムな値(CORP)が指定されている場所に追加された追加のidemである国からオプション(Special)を選択します。 DropDownList
ListItem
_DropDownListCountry.Items.Insert(1, new ListItem("Special", "CORP"));
予想されるユーザーが特定の年の_DropDownListCountryから上記のオプションを選択すると、2つのアイテムが別のアイテムDropDownList
(_DropDownListCenter)に入力される必要があります。アイテムはリストに含まれている必要があります(例:1111および2222)。年ごとにセンターや企業との関係があります。
問題:データベースには2つのセンターがありますが、年が異なるため、結果は(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;
}