3

T-SQLクエリを使用する:

select [ProductNumber] ,max([ProductRevNumber])
from Products  
group by [ProductNumber]

LINQクエリを試行しました:

ProductsDBContext.Products.GroupBy(x => x.ProductRevNumber)
                          .Select(group => ProductNumber, 
                                           ProductRevNumber = group.Max(x => x.ProductRevNumber));

ラムダクエリは機能しません。

4

2 に答える 2

6

私はこれがあなたが求めているものだと思います:

var latestProducts = ProductsDBContext.Products
    .GroupBy(p => p.ProductNumber).Select(g => new 
    {
        ProductNumber = g.Key,
        MaxProductRevNumber = g.Max(p => p.ProductRevNumber))
    });
于 2012-07-13T16:28:36.977 に答える
2
from p in db.Products
group p by p.ProductNumber into g
select new
{
    ProductNumber = g.Key,
    ProductRevNumber = g.Max(p => p.ProductRevNumber)
};
于 2012-07-13T16:35:00.257 に答える