如何使用lambda运算符转换以下查询

时间:2011-08-30 10:27:44

标签: linq-to-objects

var a = from u in Users
                group u by new {u.UserName,u.Address,u.City,u.State} into abc
                select new
                {
                    Count=abc.Count(),
                    Name= abc.Key.UserName,
                    Address=abc.Key.Address,
                    State=abc.Key.State,
                    City=abc.Key.City   
                };

1 个答案:

答案 0 :(得分:2)

试试这个

var a = users.GroupBy(u => new {u.Username, u.Address, u.City, u.State})
        .Select(abc => new
                          {
                               Count = abc.Count(),
                               Name = abc.Key.Username,
                               Address = abc.Key.Address,
                               State = abc.Key.State,
                               City = abc.Key.City
                           });
相关问题