我正在看一些關於linq的微軟網站的例子,我看到一個我需要修改的例子!SelectMany in Linq to entity
http://msdn.microsoft.com/en-us/vcsharp/aa336758.aspx#SelectManyCompoundfrom3
public void Linq16()
{
List<Customer> customers = GetCustomerList();
var orders =
from c in customers
from o in c.Orders
where o.OrderDate >= new DateTime(1998, 1, 1)
select new { c.CustomerID, o.OrderID, o.OrderDate };
ObjectDumper.Write(orders);
}
有選擇retrives在客戶,訂單ID和訂購日期的insted的我想選擇的客戶ID和包含該用戶的所有訂單System.Collection.Generic.List<int>
!基本上我想通過CustomerID對我的訂單進行分組,但我注意到linq到實體不允許.ToList(object)
在select中。
我想是這樣的......
List<Customer> customers = GetCustomerList();
var orders =
from c in customers
from o in c.Orders
where o.OrderDate >= new DateTime(1998, 1, 1)
select new xpto
{
TheCostumerID = c.CustomerID,
CostumerOrders = o.Select(i=>i.OrderID).ToList(),
};
...但.ToList()是一個很大的問題,至少對我來說。
我試圖找出解決方案,但迄今爲止我什麼都沒做!
請幫幫我。
「ToList」的問題是什麼? – 2010-05-18 16:47:47
.ToList()裏面的選擇在linq to實體似乎不工作! – Brazeta 2010-05-24 10:40:04