Why this Linq doesn't work (Error translating Linq expression to URI: Can only specify query options (orderby, where, take, skip)

随声附和 提交于 2019-12-12 18:23:03

问题


var query = from ch in Client.wcf.context.CashHeading
    where ch.Id_customer == customern//cc.Id
    from cs in Client.wcf.context.Cash
    where cs.Id_cashheading == ch.Id
    from gg in Client.wcf.context.Good
    where gg.Id == cs.Id_good
    select gg.Price.Value;

I'm getting inner error processing it:

Error translating Linq expression to URI: Can only specify query options (orderby, where, take, skip) after last navigation.

I can't understand why, full sources Here, on GitHub


回答1:


Basically, you have to condense your where clause into a single where clause after all of the navigations (from) have been performed, like so:

var query = 
    from ch in Client.wcf.context.CashHeading
    from cs in Client.wcf.context.Cash
    from gg in Client.wcf.context.Good
    where 
        ch.Id_customer == customern && //cc.Id
        cs.Id_cashheading == ch.Id &&
        gg.Id == cs.Id_good
    select gg.Price.Value;

Granted, this doesn't seem optimal, as it would seem that it's going to do cross join all of the tables and then perform the filtering, but remember, you're probably dealing with IQueryable<T> interface implementations, meaning that this will more than likely be interpreted and then optimized by whatever handles the translated queries.



来源:https://stackoverflow.com/questions/11577458/why-this-linq-doesnt-work-error-translating-linq-expression-to-uri-can-only-s

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