1
我先使用EF5代碼。當我執行我的查詢:EF5:LINQ to Entities無法識別該方法System.Nullable System.Decimal中位數
var priceIndexQuery = from r in unitOfWork.Repository<StockIndexPriceResult>()
where request.CalculateModel.StockCompanies.Contains(r.StockCompanyId)
&& r.StockIndexId == request.CalculateModel.StockIndexId
&& r.ResultDate >= dateFiveYearsAgo
orderby r.ResultDate descending
group r by r.ResultDate
into g
select g;
然後:
var query = priceIndexQuery.Select(g => new CalculateAggregateModel
{
ResultDate = g.Key,
Value = g.Median(p => p.Result ?? 0),
PeriodType = "Day"
});
resultData = query.ToList();
我上query.ToList錯誤時拋出();到目前爲止我所知道的是MSSQL無法執行中位數函數。我有辦法解決它嗎?
你可以叫'AsEnumerate()'之前,你的選擇。這會強制查詢在此時執行數據庫**,然後在內存中繼續。確保只選擇儘可能多的數據,而不是更多。 – user3038092