2012-07-20 47 views
3

這是我的失敗代碼錯誤翻譯LINQ表達式到URI:該方法「選擇」不支持

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

其他信息:該方法的「選擇」不被支持。

,這解決了錯誤: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查詢有做工精細

error:+ 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}

+0

從堆棧跟蹤/代碼它看起來像日期爲空,但你可以檢查一個調試器。日期是否可以空?如果是,請嘗試使用date.HasValue && date ... – 2012-07-20 06:56:06

+0

否,查詢結果中沒有空值 – Cynede 2012-07-20 07:04:18

+0

您確定'c!= null'嗎? – Henrik 2012-07-20 07:06:17

回答

2

可能query包含null。嘗試

where x != null && x.CustomerID == c.Id 
相關問題