Использование функции linq Zip позволяет объединить эти два подмассива в один. Ниже приведен пример получения максимальной версии для каждой версии:
void Main()
{
var data = GetData();
var maxRevisions = data
.Select(x => new { Document = x, KeyValue = x.Key.Zip(x.Value, (k, v) => new { Key = k, Value = v }) })
.GroupBy(x => new { Version = x.KeyValue.First(kv => kv.Key == "version").Value })
.Select(x => new { Version = x.Key.Version, MaxRevision = x.Max(y => y.KeyValue.First(kv => kv.Key == "revision").Value) })
.ToList();
maxRevisions.ForEach(mr => Console.WriteLine($"Version: {mr.Version} - MaxRevision: {mr.MaxRevision}"));
}
public class Document
{
public int Id { get; set; }
public string Description { get; set; }
public List<String> Key { get; set; }
public List<String> Value { get; set; }
}
public static List<Document> GetData()
{
return new List<Document> {
new Document {
Id = 1,
Description = "one-one",
Key = new List<string> { "version", "revision", "otherkey" },
Value = new List<string> { "1.0", "1", "othervalue" }
},
new Document {
Id = 1,
Description = "one-two",
Key = new List<string> { "version", "revision", "otherkey" },
Value = new List<string> { "1.0", "2", "othervalue" }
},
new Document {
Id = 1,
Description = "one-three",
Key = new List<string> { "version", "revision", "otherkey" },
Value = new List<string> { "1.0", "3", "othervalue" }
},
new Document {
Id = 1,
Description = "two-one",
Key = new List<string> { "version", "revision", "otherkey" },
Value = new List<string> { "2.0", "1", "othervalue" }
}};
}
Результатом будет следующее:
Version: 1.0 - MaxRevision: 3
Version: 2.0 - MaxRevision: 1