Use Linq To Entities subquery within Select clause to fetch a field value

爱⌒轻易说出口 提交于 2019-12-25 03:12:49

问题


Can I use a Linq To Entities subquery within a (linq to entities) Select clause to fetch a filed value like this:

var a = someIQueryable;
var b = IQueryable_2.Select((a,i)=> new Model
{
SomeFiled = someIQueryable.Where(w=>w.AA==a.AA).Select(w=>w.Calls).First()
}).ToList();

I am getting "Cannot translate method into store expression".

Is there any way to do this ?


回答1:


I think the issue is caused by Select method (though you could probably provide more details). I'm not sure why you use Select overload with index parameter if you do not use it. Use another Select overload:

var b = IQueryable_2.Select(a => new Model
                     {
                       SomeFiled = someIQueryable.Where(w=>w.AA==a.AA)
                                                 .Select(w=>w.Calls).First()
                     }).ToList();


来源:https://stackoverflow.com/questions/5485848/use-linq-to-entities-subquery-within-select-clause-to-fetch-a-field-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!