将Linq表达式转换为URI的错误:不支持“选择”方法

时间:2012-07-20 06:39:32

标签: c# .net linq wcf-data-services odata

这是我失败的代码

        var query = from gg in Client.wcf.context.Good
                    from cc in Client.wcf.context.Customer
                    from ch in Client.wcf.context.CashHeading
                    from cs in Client.wcf.context.Cash
                    where ch.Id_customer == cc.Id
                    where cs.Id_cashheading == ch.Id
                    where gg.Id == cs.Id_good
                    select new CustomerOrderResult {
                        CustomerID = cc.Id,
                        Price = gg.Price.HasValue ? gg.Price.Value : 0,
                        Date = ch.Date.HasValue ? ch.Date.Value : DateTime.Now
                    };
        List<CustomerOrderResult> qqq = query.ToList();

其他信息:方法&#39;选择&#39;不受支持。

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

查询是另一个linq,它的WCF数据客户端到服务器(实体)应用程序的完整源文件是Here, on GitHub

其他linq查询工作正常

错误:+ query {Error translating Linq expression to URI: The method 'Select' is not supported.} System.Linq.IQueryable<CustomerOrderResult> {System.Data.Services.Client.DataServiceQuery<CustomerOrderResult>.DataServiceOrderedQu ery}

1 个答案:

答案 0 :(得分:1)

可能query包含null。尝试

where x != null && x.CustomerID == c.Id