我试图使用动态列的LINQ创建一个Pivot。我在SQL Server中创建了一个枢轴,您不知道将使用哪些列。但不知道如何将其转换到LINQ中。有人有链接给我吗?
欢呼
List<CustData> myList = GetCustData();
var query = myList
.GroupBy(c => c.CustId)
.Select(g => new {
CustId = g.Key,
Jan = g.Where(c => c.OrderDate.Month == 1).Sum(c => c.Qty),
Feb = g.Where(c => c.OrderDate.Month == 2).Sum(c => c.Qty),
March = g.Where(c => c.OrderDate.Month == 3).Sum(c => c.Qty)
});
这是David B在这个url中的回答