C# 具有分组和最大日期的Linq查询
所以我需要从ProductVersions集合中获取列表,其中最新的ReleaseDate按ProductId和VersionType分组 为组使用匿名类型:C# 具有分组和最大日期的Linq查询,c#,linq,C#,Linq,所以我需要从ProductVersions集合中获取列表,其中最新的ReleaseDate按ProductId和VersionType分组 为组使用匿名类型: class ProductVersion { string ProductId string VersionNumber VersionType versionType DateTime ReleaseDate } 您必须将ProductVersion的属性和字段设置为公共,否则无法访问它们。请为组使用匿名类型:
class ProductVersion
{
string ProductId
string VersionNumber
VersionType versionType
DateTime ReleaseDate
}
您必须将
ProductVersion
的属性和字段设置为公共
,否则无法访问它们。请为组使用匿名类型:
class ProductVersion
{
string ProductId
string VersionNumber
VersionType versionType
DateTime ReleaseDate
}
var prodVersionList = AllProductVersions
.GroupBy(pv => new { pv.ProductId, pv.versionType })
.Select(g => g.OrderByDescending(pv => pv.ReleaseDate).First())
.ToList();
您必须将ProductVersion
的属性和字段公开
,否则无法访问它们
var prodVersionList = AllProductVersions
.GroupBy(pv => new { pv.ProductId, pv.versionType })
.Select(g => g.OrderByDescending(pv => pv.ReleaseDate).First())
.ToList();