當我執行下面的代碼:LINQ到實體無法識別方法「System.Linq.IQueryable`1
IHotelDataAccess _hotelDataAccess= new HotelDataAccess(_entities);
int myVal = (from u in _hotelDataAccess.GetHotelsByCityId(19)
select u).Count();
返回設爲myVal如預期的整數值,但如果我嘗試並返回IQueryable的作爲下面
return (from geoLocation in _entities.ViewGeographyLocation
where geoLocation.CountryCode == countryCode
orderby geoLocation.SortOrder, geoLocation.CityName
select new ContinentModel
{
ContinentCode = geoLocation.ContinentCode,
ContinentName = geoLocation.ContinentName,
CountryCode = geoLocation.CountryCode,
CountryName = geoLocation.CountryName,
CityId = geoLocation.CityId,
CityName = geoLocation.CityName,
CityCode = geoLocation.CityName,
TotalCount = ((from u in _hotelDataAccess.GetHotelsByCityId(19)
select u).Count())
});
我得到的錯誤:
LINQ到實體無法識別方法 「SYST em.Linq.IQueryable`1 [DestKosher.Model.HotelModel] GetHotelsByCityId(的Int32)」方法,和這種方法不能被翻譯成 商店表達。
該方法hotelDataAccess.GetHotelsByCityId(19)返回IQueryable。任何想法,幫助或解決方案將不勝感激。問候,
馬丁
UPDATE:
該查詢最初設置,查看是否通過將一個整數到功能GetHotelsByCityId會工作。不過,我想最終做的是:
return (from geoLocation in _entities.ViewGeographyLocation
where geoLocation.CountryCode == countryCode
orderby geoLocation.SortOrder, geoLocation.CityName
select new ContinentModel
{
ContinentCode = geoLocation.ContinentCode,
ContinentName = geoLocation.ContinentName,
CountryCode = geoLocation.CountryCode,
CountryName = geoLocation.CountryName,
CityId = geoLocation.CityId,
CityName = geoLocation.CityName,
CityCode = geoLocation.CityName,
TotalCount = ((from u in _hotelDataAccess.GetHotelsByCityId(geoLocation.CityId)
select u).Count())
});
不要忘記給予好評和認可它是否適合您標記的答案... –
你可以看看我的更新。問候, – user1124937