【发布时间】:2012-04-13 09:19:56
【问题描述】:
我创建了一个表,并将其插入
var CurrTable;
表格如下所示:
SaleID | ProductID | ProductName
1 | 1 | Book
1 | 2 | Notebook
2 | 3 | Guitar
2 | 4 | Piano
我有两个类,ProductInfo 和 SaleInfo:
public class ProductInfo
{
int ProductID;
string ProductName;
}
public class SaleInfo
{
int SaleID;
List<ProductInfo> products;
}
我只想用数据填写 SaleInfo (List<SaleInfo>) 列表...
我写的查询是这样的:
List<SaleInfo> results = (from s in CurrTable.AsEnumerable()
group s by new { s.SaleId} into g
select new SaleInfo
{
SaleID = g.Key.SaleId,
Products = (*...*)
}).ToList();
但我不知道在(*...*) 中写什么。我不想再做一次选择,因为我已经有了数据。我只是想在产品列表中填写列表,这就是我使用 group 功能的原因。
我该怎么做?
【问题讨论】:
标签: linq entity-framework linq-to-sql linq-to-entities linq-to-objects