2011-08-30 48 views
1
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 
       }; 

回答

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 
          });