2012-04-19 56 views
1

我正在使用linq to Entity通過將它們加入到不同的表中來檢索數據,但我也想將它們分組在字段problemDesc爲了擺脫不必要的重複條目相同的問題。如何將linq中的查詢分組爲實體

這裏是代碼:

using (AssistantEntities context = new AssistantEntities()) 
     { 
      var problems = context.tblProblems; 
      var customers = context.tblCustomers; 

      var query = 
      from problem in problems 
      join customer in customers 
      on problem.CustID equals customer.custID 
      where problem.IsActive == true 
      orderby customer.isMonthlyService == true descending 
      select new 
      { 
       problemID = problem.problemID, 
       ProblemCreateDate = problem.ProblemCreateDate, 
       CustID = problem.CustID, 
       name = customer.name, 
       isMonthlyService = customer.isMonthlyService, 
       StationName = problem.StationName, 
       problemDesc = problem.problemDesc, 
       LogMeIn = problem.LogMeIn 
      }; 
      return query.ToList(); 
     } 

我爲了使用在GridView作爲一個DataSource該名單做query.toList()。 如果可能的話,還要添加一個計算重複問題的字段。

+0

可能重複的[LINQ的分組方式](http://stackoverflow.com/questions/1153458/linq-group-by)和[一堆其他的問題](HTTP:// WWW。 bing.com/search?q=site%3Astackoverflow.com+linq+group+by&go=&qs=n&sk=&form=QBRE) – jrummell 2012-04-19 14:29:16

+0

這看起來像我正在尋找的,謝謝 – 2012-04-19 19:33:55

回答