2016-09-01 6 views
1

でLINQクエリから特定のフィールドを選択し、それはこのようになりますクラスStepDTOを作成しました。ここで私は私のLINQクエリを最適化するために必要なリスト

は疑問がselect句でStepDTOインスタンスを作成する代わりに、全体l.H_Scenario.Stepsを選択することで、クエリList<List<StepDTO>>から取得する方法であるクラスStep

private class Step 
     { 
      private System.Int64 id; 
      private System.Int32 responseTime; 
      private H_Scenario h_Scenario; 
      /other fields*/ 
     } 

とクラスStepDTO

private class StepDTO 
     { 
      private System.Int64 id; 
      private System.Int32 responseTime; 
      private H_Scenario h_Scenario; 
     } 

です。

+0

を親切にもう少し詳しく説明。私はあなたの願いを得ていません... –

答えて

2

Selectを使用して、新しいオブジェクトインスタンスを作成するだけで済みます。ここに行く:

List<List<Step>> steps = (from LoadTest l in monitoringTask.LoadTests 
        where (l.DateStart > (start - Core.session.timeSpanClientServer) 
    && l.DateStart < (stop - Core.session.timeSpanClientServer)) 
        orderby l.DateStart ascending 
        select (l.H_Scenario.Steps 
           .Where(x => x.IsActivInGlobalApdexCounting == true)) 
           //Here is you creating your DTO 
           .Select(x => new StepDTO 
            { 
              id = x.id 
              responseTime = x.responseTime 
              h_Scenario = x.h_Scenario 
            }) 
           .ToList()).ToList(); 
1
select (l.H_Scenario.Steps.Where(x => x.IsActivInGlobalApdexCounting == true)).Select(step => new StepDto { // assign values here}).ToList() 
関連する問題