none
Right Outer Join RRS feed

  • Question

  • Joins has never been my strongest point; now i need to translate SQL to linq i am lost:

    SELECT        	
     dbo.sbDierDierGroep.Id, 	
     dbo.sbDierGroep.Id AS Expr1, 	
     dbo.sbDierGroep.Naam, 	
     dbo.sbDierDierGroep.DierId
    FROM            	
     dbo.sbDierDierGroep 
    RIGHT OUTER JOIN	
     dbo.sbDierGroep ON 	
     dbo.sbDierDierGroep.DierGroepId = dbo.sbDierGroep.Id
    WHERE        	
     (dbo.sbDierDierGroep.DierId = '32364c90-d14c-4991-b1bc-aefd5e941275') OR  	
     (dbo.sbDierDierGroep.DierId IS NULL)

    If you 'see' it at once, plz give it a shot.


    • Edited by W. Luijk Friday, August 7, 2015 2:57 PM
    Friday, August 7, 2015 12:00 PM

Answers

  • The basic pattern looks like this:

    var recs = (from rightside in dbContext.RightTable
                join leftside in dbContext.LeftTable on rightside.ID equals leftside.RightsideForiegnKeyID into rlJoin
                from JoinedLeftRecs in rlJoin.DefaultIfEmpty()
                select new {JoinedLeftRecs.ColumnName, JoinedLeftRecs.ColumnName2, rightside.columname1  });

    Hope this helps.

    -james

    Tuesday, August 11, 2015 6:44 PM

All replies

  • I would suggest download LINQPAD and try it.

    Rajat Jaiswal

    Friday, August 7, 2015 1:50 PM
  • Hi Rajat,

    I did download and install LinqPad's but can't find a method from SQL to LINQ but only the other way around. What i need to construct is a RIGHT OUTER JOIN with where...





    • Edited by W. Luijk Friday, August 7, 2015 2:54 PM
    Friday, August 7, 2015 2:50 PM
  • The basic pattern looks like this:

    var recs = (from rightside in dbContext.RightTable
                join leftside in dbContext.LeftTable on rightside.ID equals leftside.RightsideForiegnKeyID into rlJoin
                from JoinedLeftRecs in rlJoin.DefaultIfEmpty()
                select new {JoinedLeftRecs.ColumnName, JoinedLeftRecs.ColumnName2, rightside.columname1  });

    Hope this helps.

    -james

    Tuesday, August 11, 2015 6:44 PM