4
我正在通过实体数据模型连接和访问的两个表上写入group by子句。我无法迭代匿名类型,有人可以帮我解决问题。在匿名类型上编写分组
public string GetProductNameByProductId(int productId)
{
string prodName=string.Empty;
using (VODConnection vodObjectContext = new VODConnection())
{
var products = from bp in vodObjectContext.BFProducts
join bpf in vodObjectContext.BFProductMasters on bp.ProductMasterId equals bpf.ProductMasterId
where bp.ProductId == productId
group bp by new { ProductId = bp.ProductId, ProductName = bp.ProductName, ProductMasterName=bpf.ProductMasterName} into newInfo
select newInfo;
//Want to iterate over products or in fact need to get all the results. How can I do that? Want productmastername property to be set in prodName variable by iterating
return (prodName);
}
}
谢谢Jon。我是LINQ的新手,并且正在尝试使用一些基本教程来做这些事情,所以一个糟糕的代码。这个group.key非常有帮助。万分感谢。 – 2011-04-18 13:46:17