none
Left Join Linq query RRS feed

  • Question

  • Table VascoToken

    VascoTokenId

    PhysicalSerialNumber

    LogicalSerialNumber

     

    Table SbsUser

    Username

    FullName

    VascoTokenId

     

    SELECT * FROM Vascotoken V

     left JOIN SBSUSER S on V.VascoTokenId = S.VascoTokenId

    order by v.PhysicalSerialNumber

     

    which selects all the fields from vascoToken and SbsUser

     

    my linq query

     

     var _tepData = from v in _sbsUserDataContent.VascoTokens

                              join u in _sbsUserDataContent.SbsUsers

                              on v.VascoTokenId equals u.VascoTokenId into Temp

                              from vus in Temp.DefaultIfEmpty()

                              select vus;

     

     

     

    which is selected only from SBSuser TABLE

     

    SO what is the change I have to make the LINQ querry to match with the Sql query

     

     

    Thanks

    Thursday, January 26, 2012 11:56 AM

Answers

All replies

  • Hi Rushdy.

    This article explains how to make left join / right join with LINQ http://codingsense.wordpress.com/2009/03/08/left-join-right-join-using-linq/

    Hope this will be useful.


    "En los momentos de crisis, sólo la imaginación es más importante que el conocimiento"
    Thursday, January 26, 2012 2:30 PM
  • Hi Rushdy;

    You also need to return the values from the table VascoTokens as well, see the select statement below.

    var _tepData = from v in _sbsUserDataContent.VascoTokens 
                   join u in _sbsUserDataContent.SbsUsers
                       on v.VascoTokenId equals u.VascoTokenId into Temp
                   from vus in Temp.DefaultIfEmpty()
                   select new { v, vus };
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Rushdy Najath Friday, January 27, 2012 9:28 AM
    • Unmarked as answer by Rushdy Najath Thursday, February 9, 2012 4:02 PM
    Thursday, January 26, 2012 3:58 PM
  • thanks fernando
    Friday, January 27, 2012 9:28 AM
  •  

    Not a problem Rushdy, glad I was able to help.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Friday, January 27, 2012 2:31 PM