Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有分组和最大日期的Linq查询_C#_Linq - Fatal编程技术网

C# 具有分组和最大日期的Linq查询

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

所以我需要从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
}
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();