2016-05-26 5 views
0

私はカップルテーブルに参加し、各ステータスのカウントを取得しようとしています。linqを使用して複数のテーブルからデータをグループ化する

ID、タイトル:

EmployeeEvaluationsStatusesは、次のフィールドがあります。 EmployeeEvaluationsStatuses表情で

データのように:

Id Title 
1 New - Incomplete 
2 Submitted – All Docs 
3 Approved 
4 Rejected - Need More Info 
5 Qualified 

私は次のように結果を取得したい:

StatusCount Status 

60   New - Incomplete 
42   Submitted – All Docs 
20   Qualified 

をここに私のクエリはどのように見えるかです:

from ep in EmployeePositions.Where(a => a.CorporateId == 1596) 
join ee in EmployeeEvaluations.Where(e => e.TargetGroupId != null) on ep.EmployeeId equals ee.EmployeeId 
join ees in EmployeeEvaluationStatuses on ee.EvaluationStatusId equals ees.Id 

group ees by ees.Id into g 
select new 
{ 
    StatusCount = g.Count() 
    ,Status= ees .title  
} 

私はエラーが発生しました。「The name 'ees' does not exist in the current context

私はナビゲーションプロパティについてはわかりません。

public partial class WotcEntities : DbContext 
    { 
     public WotcEntities() 
     : base(hr.common.Database.EntitiesConnectionString("res://*/ef.WotcModel.csdl|res://*/ef.WotcModel.ssdl|res://*/ef.WotcModel.msl", "devConnection")) 
     { 
     } 

     protected override void OnModelCreating(DbModelBuilder modelBuilder) 
     { 
      throw new UnintentionalCodeFirstException(); 
     } 


     public virtual DbSet<EmployeeEvaluations> EmployeeEvaluations { get; set; } 
     public virtual DbSet<EmployeeEvaluationStatus> EmployeeEvaluationStatus { get; set; } 
     public virtual DbSet<EmployeePositions> EmployeePositions { get; set; } 

    } 




public partial class EmployeeEvaluationStatus 
    { 
     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] 
     public EmployeeEvaluationStatus() 
     { 
      this.EmployeeEvaluations = new HashSet<EmployeeEvaluations>(); 
      this.Vouchers = new HashSet<Vouchers>(); 
     } 

     public int Id { get; set; } 
     public string Title { get; set; } 

     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] 
     public virtual ICollection<EmployeeEvaluations> EmployeeEvaluations { get; set; } 
     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] 
     public virtual ICollection<Vouchers> Vouchers { get; set; } 
    } 
+0

を使用してナビゲートする必要があり、あなたのエンティティ間のナビゲーションプロパティを持っていますか?エンティティクラスを表示できますか? –

+0

私はentityFrameworkの下に存在するエンティティクラスを追加しました。 – BumbleBee

+0

あなたはナビゲーションプロパティを持っているようです。あなたは 'EmployeePositions'と' EmployeeEvaluations'を表示できますか? –

答えて

1

あなたのgroup byで複合キーを使用してg.Key

from ep in EmployeePositions.Where(a => a.CorporateId == 1596) 
join ee in EmployeeEvaluations.Where(e => e.TargetGroupId != null) on ep.EmployeeId equals ee.EmployeeId 
join ees in EmployeeEvaluationStatuses on ee.EvaluationStatusId equals ees.Id 

group ees by new { ees.Id, ees.title } into g 
select new 
{ 
    StatusCount = g.Count(), 
    Status= g.Key.title 
} 
関連する問題