2012-04-19 6 views
1

linqを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にそのリストを使用するために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

+0

これは私が探しているもののようです –

答えて