我有一个我创建的表,我将它插入到
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;
}
我只想List<SaleInfo>
用数据填充 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 功能的原因。
我怎样才能做到这一点?