我無法理解爲什麼在下面的代碼中出現錯誤。我確信我缺少一些簡單的東西,但我需要幫助理解。Linq。使用LinqPad選擇方法問題
我一直在使用LinqPad運行LinqToSql此代碼。
我在LinqPad以下代碼:
有三個表參與:出貨量,ShipmentDetails和ShipmentWeights。所有三個表都通過出貨單的PK來鏈接。
在這段代碼,最終查詢(「權重」)失敗,出現錯誤:「不支持例外:與當地館藏查詢不被支持。」我收集了LinqToSql中的某些東西不支持使用.Contains,但我不明白查詢名爲「Details」的查詢是如何工作的。這似乎是對我來說同樣的一種查詢。有人可以填補我的空白嗎?
對於那些誰不熟悉LinqPad中,使用.dump方法是IQueryable的只是一個擴展方法,打印出格式化的方式的內容。
var shipments = Shipments.Where(s => s.OrderID == "Some OrderID");
shipments.Dump("Shipments");
var shipmentIds = shipments.Select(s => s.ShipmentID);
shipmentIds.Dump();
//This query works. What is different about this query than the one that fails?
var shipmentDetails = ShipmentDetails.Where(d => shipmentIds.Contains(d.ShipmentID));
shipmentDetails.Dump("Details");
var detailShipmentIds = shipmentDetails.Select(sd => sd.ShipmentID);
detailShipmentIds.Dump();
//This is the query that generates the error
var shipmentWeights = ShipmentWeights.Where(w => detailShipmentIds.Contains(w.ShipmentID));
shipmentWeights.Dump("Weights");
http://stackoverflow.com/questions/1084339/working-around-linqtosqls -query-with-local-collections-are-not-supported-exce –