2016-02-11 1 views
1

J'ai un morceau de code où je veux grouper par deux champs et faire un ToDictionary dessus avec les deux champs comme une clé en tuple. Je ne suis pas sûr de la syntaxe. Voici ce que j'ai, Mais le problème est qu'il crée un Tuple avec un seul objet.Grouper par deux colonnes et faire un ToDictionary avec un Tuple comme clé C# Linq

var count = this.Db.Query<EmployeeCount>(@"select 
      employername, ein, month, headcount 
      from employerInfo A inner join MonthlyInfo B on (A.Id = B.Id) 
      where A.ClientId = @Client", 
      new { run.Client }) 
      .GroupBy(r => new { r.EIN, r.EmployerName}) 
      .ToDictionary(pair => Tuple.Create<string>(pair.Key.ToString()), pair => pair.ToDictionary(r => (Months)r.month, r => r.headcount)); 

Et ma classe EmployeeCount est

private class CountQuery 
    { 
     public string EmployerName; 
     public string EIN; 
     public int Month; 
     public int HeadCount; 
    } 

J'essaie de faire un Tuple.Create, mais je ne suis pas sûr de savoir comment informer que les params seraient EIN et Employername pour le Tuple.

+0

Pour votre information, vous devez utiliser de POCO propriétés ** ** publiques, à savoir la place des champs ** ** avec OrmLite. – mythz

Répondre

3

Je pensais que ce moi-même comme ci-dessous

var count = this.Db.Query<EmployeeCount>(@"select 
     employername, ein, month, headcount 
     from employerInfo A inner join MonthlyInfo B on (A.Id = B.Id) 
     where A.ClientId = @Client", 
     new { run.Client }) 
     .GroupBy(r => new { r.EIN, r.EmployerName}).ToDictionary(pair => Tuple.Create<string,string>(pair.Key.EIN.ToString(),pair.Key.EmployerName), pair => pair.ToDictionary(r => (Months)r.ReportingMonth, r => r.FTECount))