查询给出了错误的结果实体框架

时间:2013-12-10 03:10:32

标签: sql entity-framework c#-4.0

我正在使用下面的查询,它在Linqpad中给我一个正确的结果,但是当我在EF中使用相同的查询时,它给我错误的结果或浏览器上的多个结果。在查询中我从商店程序返回记录。

((from sp in spCV(12).AsEnumerable()                     
                  select new
                  {
                      HRUserID = sp.HRUserID,
                      FirstName = sp.FirstName,
                      DOB = sp.DOB,                                                    
                      Gender = sp.Gender,                          
                      Qualification = sp.Qualification,
                      Institute = sp.Institutes,                        
                      StartDate = sp.StartDate,
                      EndDate = sp.EndDate,
                      FieldofStudy = sp.FieldofStudy,                        
                      Course = sp.Course,
                      CFieldofStudy = sp.CFieldofStudy,
                      CInstitute = sp.Institute,
                      CStartDate = sp.CStartDate,
                      CEndDate = sp.CEndDate,                          
                  })
             .GroupBy(x => new
             {
                 x.HRUserID,                   
                 x.DOB,                     
                 x.FirstName,
                 x.Gender,                   
             }).Distinct()
             .Select(x => new 
             {                    
                 HRUserID = x.Key.HRUserID.Value,                  
                 FirstName = x.Key.FirstName,                     
                 DOB = x.Key.DOB ?? x.Key.DOB.Value,                     
                 Gender = x.Key.Gender,
                 AcademicInformations = x.Select(z => new 
                 {
                     Qualification = z.Qualification,
                     Institute = z.Institute,                     
                     StartDate = z.StartDate,
                     EndDate = z.EndDate,    
                 }).Distinct(),
                 ProfessionalTrainings = x.Select(pt => new 
                 {
                     Course = pt.Course,
                     FieldofStudy = pt.CFieldofStudy,
                     Institute = pt.CInstitute,
                     StartDate = pt.CStartDate,
                     EndDate = pt.CEndDate,                       
                 }).Distinct(),                                      
             })).FirstOrDefault()

enter image description here

0 个答案:

没有答案