我无法理解为什么在下面的代码中出现错误。我确信我缺少一些简单的东西,但我需要帮助理解。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 –