תשובה Linq Equivalent of SQL (RIGHT OUTER JOIN)

  • יום חמישי 22 מרץ 2012 07:22
     
     

    select tb2.Month,tb2.Year,isnull(tb1.Count,0) from SSRS.dbo.Table_1 tb1
    right outer join SSRS.dbo.Table_2 tb2
    on tb1.Month =tb2.Month

    Please tellme the linq equiv of above sql query 

כל התגובות

  • יום חמישי 22 מרץ 2012 10:53
     
     

    from tb2 in db.Table_2
    join tb1 in db.Table_1 on tb2.Month equals tb1.Month into tb1_join
    from tb1 in tb1_join.DefaultIfEmpty()
    select new {
      tb2.Month,
      tb2.Year,
      Column1 = ((System.Int32?)tb1.Count ?? (System.Int32?)0)
    }
    this is the linq equiv ... but it is throwing null reference exception.

    Please Help...

  • יום שישי 23 מרץ 2012 03:18
    מנחה דיון
     
     תשובה

    Hi LINK_me_with_LINQ,

    Welcome to MSDN Forum.

    After joining the tables, please check if the tb1 and tb2 are not null. Based on the exception, I think it may caused by any of them are null, so you can't get tb2.Month and tb2.Year or tb1.Count.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us