我尝试从 tblAccomodation 获取所有邮政编码的列表以放入组合框中。
例如
8630 - Veurne
8660 - De Panne
8670 - Koksijde
这是两张表之间的关系: tblCity.ID = tblAccomodation.CityID
TblCity 包含 (ID, Zipcode, Name, UpName, StructCode) TblAccomodation 包含 (ID, CityID, Name, .....)
当然,有多个具有相同 CityID 的住宿,所以我尝试使用 DISTINCT()。但它不起作用。
public static Dictionary<int, string> getPostals()
{
Dictionary<int, string> Zipcodes = new Dictionary<int, string>();
var AllAccomodations = (from oAccomodation in new DBReservationDataContext().tblAccomodations
orderby oAccomodation.Name ascending
select oAccomodation).ToList();
foreach (tblAccomodation item in AllAccomodations.Distinct())
{
Zipcodes.Add(item.CityID, clsCities.getCityInfo(item.CityID, "Zipcode") + ' ' + clsCities.getCityInfo(item.CityID, "UpName"));
}
return Zipcodes;
}
我需要改变什么?