将 Linq 表达式转换为 URI 时出错:不支持 'Select' 方法。

3

这是我的失败代码

        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();

附加信息:方法“Select”不受支持。

这个错误可以通过以下方式解决:为什么这个Linq不起作用(错误将Linq表达式转换为URI:只能指定查询选项(orderby、where、take、skip)

查询是另一个Linq,总体上它是WCF数据客户端到服务器(实体)应用程序的完整源文件,在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


从堆栈跟踪 / 代码来看,日期似乎为null,但您可以使用调试器进行检查。日期是否可为空?如果是,请尝试使用date.HasValue && date... - just.another.programmer
没有,查询结果中没有任何可空项。 - cnd
你确定 c != null 吗? - Henrik
是的,我编辑了代码,在那里出现了内部异常。 - cnd
1个回答

1

可能 query 包含了 null。请尝试

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接