0

私のアプリケーションでは、特定のユーザーの履歴の詳細を表示したいと考えています。ユーザーは多くの仕事を持つことができ、さまざまな役割を持つさまざまなプロモーションにアクセスできます。

こういう歴史を見せられるようになりたい

       昇格        _

2012 アシスタント昇進 2012

2013年マネージャー昇進2013年

このクエリを試しました(エンティティにLinqを使用しています)

var query = (from u in context.Users
             join j in context.Jobs.Where(jo => jo.JobStartDate.HasValue) on u.UserID equals j.UserID into jobs
             from job in jobs.DefaultIfEmpty()
             join uir in context.UserInRoles on u.UserID equals uir.UserID into userInRoles
             from userInRole in userInRoles.DefaultIfEmpty()
             join rip in context.RoleInPromotion on userInRole.RoleInPromotionID equals rip.RoleInPromotionID into roleInPromotions
             from roleInPromotion in roleInPromotions.DefaultIfEmpty()
             join p in context.Promotions.Where(pro => pro.PromotionStartDate.HasValue) on roleInPromotion.PromotionID equals p.PopulationTargetID into promotions
             from promo in promotions.DefaultIfEmpty()
             where u.UserID == userId 
             select new
             {
                 Year = job.JobStartDate.HasValue ? job.JobStartDate.Value.Year : promo.PromotionStartDate.HasValue ? promo.PromotionStartDate.Value.Year : 0,
                 JobTitle = job.JobTitle,
                 Promotion = promo.PromotionName
             }).Distinct().ToList();

しかし、ユーザーが2012年にプロモーションにアクセスできなかったにもかかわらず、これは私にこの結果をもたらしています

       昇格        _

2012年 アシスタント昇格 2013年

2013年マネージャー昇進2013年

これもやってみたけど変わらない

group new { job, promo } by new { jobYear = job.JobStartDate.Value.Year, promoYear = promo.PromotionStartDate.Value.Year } into grp
4

1 に答える 1

0

あなたはこれを試しましたか:

var query = (from u in context.Users
             join j in context.Jobs.Where(jo => jo.JobStartDate.HasValue) on u.UserID equals j.UserID into jobs
             from job in jobs.DefaultIfEmpty()
             join uir in context.UserInRoles on u.UserID equals uir.UserID into userInRoles
             from userInRole in userInRoles.DefaultIfEmpty()
             join rip in context.RoleInPromotion on userInRole.RoleInPromotionID equals rip.RoleInPromotionID into roleInPromotions
             from roleInPromotion in roleInPromotions.DefaultIfEmpty()
             join p in context.Promotions.Where(pro => pro.PromotionStartDate.HasValue) on roleInPromotion.PromotionID equals p.PopulationTargetID into promotions
             from promo in promotions.DefaultIfEmpty()
             where u.UserID == userId 
         let year=job.JobStartDate.HasValue ? job.JobStartDate.Value.Year : promo.PromotionStartDate.HasValue ? promo.PromotionStartDate.Value.Year : 0
             select new
             {
                 Year =year ,
                 JobTitle = job.JobTitle,
                 Promotion = "Promotion "+year
             }).Distinct().ToList();
于 2013-07-30T09:37:10.487 に答える