问题描述:

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();
相关阅读:
Top