1
我必須搜索記錄,其中cityname like '%United States;AK;Adak%'
並根據結果,存儲我的viewmodel對象中的列值。實體框架中的LIKE子句
我寫了下面的代碼,並且當從數字值轉換的值必須小於無窮大時導致錯誤。
zipcode=United States;AK;Adak;
var zipcd = (from u in db.ZipCodes1
where u.CityName.Contains(zipcode) && u.CityType == "D"
select u).ToList().Select(u => new Viewsearch
{
Zipcode = u.ZIPCode,
CityName = u.CityName,
stateabbr = u.StateAbbr
}).Distinct();
Viewsearch vs = (Viewsearch)zipcd;
if (zipcd.Count() > 1)
{
locations = "United States;" + vs.stateabbr + ";" + vs.CityName;
}
else if (locations == "")
{
locations = "United States;" + vs.stateabbr + ";" + vs.CityName;
}
else
{
locations = "United States;" + vs.stateabbr + ";" + vs.CityName + "," + locations;
}
if (zipcd.Count() > 3)
{
locations = locations.Replace(locations, "," + "<br>");
}
zipcode是char類型,cityname是varchar類型,citytype是char類型,在模型中所有對象都是字符串類型給我解決方案和完整錯誤消息msg無法投射類型爲' d__81'1的對象[ITClassifieds.Models.Viewsearch]'鍵入'ITClassifieds.Models.Viewsearch'。 –
DeviPhone26
2011-06-03 13:04:32
請參閱編輯 - 嘗試提供完整的異常詳細信息 - 原始問題提到「從數字值轉換時出現錯誤」 - 與您在以後的評論中不相似! – RichardW1001 2011-06-03 13:35:20