当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Summation of data, linq

问题描述:

I want to summarize the "count" field where "Room" and "object code" are equal.

Any ideas?

网友答案:

I have no idea how is your context set, what is the table name and dozen other things that are necessary to answer your question, but it will definitely use GroupBy LINQ method, something like:

var results = db.TableName.GroupBy(x => new { x.Room, x.ObjectCode })
                          .Select(g => new { g.Key.Room, g.Key.ObjectCode, Count = g.Sum(x => x.Code) })
                          .ToList();
分享给朋友:
您可能感兴趣的文章:
随机阅读: