2014-03-24 4 views
0

누군가가 내 머리를 쓰지 못하는 SQL을 도와 줄 수 있습니까? T-SQL에서 그것은 다음과 같습니다 LINQ - 매개 변수가있는 LEFT OUTER JOIN

SELECT v.errandtype 
, COUNT(s.IVRTaskType) 
FROM V_ERRANDS v 
LEFT OUTER JOIN StatisticsRequest s 
    ON s.IVRTaskType = V.IVRTaskType 
    AND s.RegistrationDate >= '2014-03-24 00:00:00.000' 
    AND s.RegistrationDate <= '2014-03-24 23:59:59.000' 
    AND s.CountryID = 0 
GROUP BY v.errandtype 

그러나 LINQ의

는 ... 그 언어는 ... 이상한 괴물, 난 그냥 그것을 얻을 해달라고한다.

대단히 감사합니다. LINQ에서

+0

[this] (http://www.thinqlinq.com/Post.aspx/Title/Left-Outer-Joins-in-LINQ-with-Entity-Framework)가 LINQ에서 왼쪽 조인에 도움이되는지 확인하십시오. –

답변

0

요청이 같이 표시됩니다 : 당신은 셀 수 있도록 왼쪽에

var statisticsRequest = yourContext.StatisticsRequest.Where(s => 
    s.RegistrationDate >= new DateTime(2014,03,24) && 
    s.RegistrationDate <= new DateTime(2014,03,25) && 
    s.CountryID == 0); 

var results = 
    from v in yourContext.V_ERRANDS 
    group v by v.errandtype into g 
    join s in statisticsRequest on s.IVRTaskType = g.FirstOrDefault().IVRTaskType 
    select new { 
     s.IVRTaskType, 
     g.Count() 
    } 
+0

도움을 주셔서 감사합니다! – user3456202

0
  • DefaultIfEmpty가, 그룹화에 대한 LINQ 쿼리 외부
  • 익명 형식을
  • DateTime 변수 가입 다른 테이블 열

DateTime start = new DateTime(2014,03,24); 
DateTime end = new DateTime(2014,03,25); 

var query = from v in context.V_ERRANDS 
      from s in context.StatisticsRequest.Where(x => x.IVRTaskType == v.IVRTaskType) 
               .Where(x => x.RegistrationDate >= start && x.RegistrationDate < end) 
               .Where(x => x.CountryID == 0) 
               .DefaultIfEmpty() 
      group new { v, s} by v.errandtype into g 
      select new 
      { 
       errandtype = g.Key, 
       count = g.Select(x => x.s.IVRTaskType).Count(), 
      }; 
+0

감사! 그것은 완벽하게 작동했습니다. – user3456202