【问题标题】:Why this Linq doesn't work (Error translating Linq expression to URI: Can only specify query options (orderby, where, take, skip)为什么此 Linq 不起作用(将 Linq 表达式转换为 URI 时出错:只能指定查询选项(orderby、where、take、skip)
【发布时间】:2012-07-20 10:23:37
【问题描述】:
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;

我在处理它时遇到内部错误:

将 Linq 表达式转换为 URI 时出错:只能指定查询 上次导航后的选项(orderby、where、take、skip)。

我不明白为什么,完整来源Here, on GitHub

【问题讨论】:

  • 我相信错误是说必须将 where 子句放在所有 3 个 froms 之后。

标签: c# linq odata


【解决方案1】:

基本上,您必须在 所有 导航 (from) 已执行后将 where 子句压缩为 单个 where 子句,如下所示:

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;

当然,这似乎不是最优的,因为它似乎会交叉连接所有表并然后执行过滤,但请记住,您可能正在处理 IQueryable<T> interface 实现,这意味着这很可能会被解释,然后由处理翻译查询的任何处理进行优化。

【讨论】:

    猜你喜欢
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多