none
Left Outer Join in vb.net LINQ RRS feed

  • Question

  • Please, Help me convert Left Join to Left Outer Join in my code:

          Dim tbCCI As DataTable = ds2.Tables("tbCCI")

          Dim tbCZY As DataTable = ds3.Tables("tbCZY")

     

          From rCZY As DataRow In tbCZY

          Join rCCI As DataRow In tbCCI

          On rCZY.Field(Of Int32)("ID_CZY") Equals rCCI.Field(Of Int32)("ID_CZY")

          Select New With

          {

          .ID_CZY = rCZY.Field(Of Int32)("ID_CZY"),

          .ID_CI = rCCI.Field(Of Int32)("ID_CI")

          }

     

    I tried a lot of examples, but nothing works... For example this:

     

          From rCZY As DataRow In tbCZY

          Group Join rCCI As DataRow In tbCCI

          On rCZY.Field(Of Int32)("ID_CZY") Equals rCCI.Field(Of Int32)("ID_CZY") Into gCCI = Group From m In gCCI.DefaultIfEmpty

          Select New With

          {

          .ID_CZY = rCZY.Field(Of Int32)("ID_CZY"),

          .ID_CI = gCCI.Field(Of Int32)("ID_CI")

          }

    I dont't know is it correct, and there is an error in last line - can't use "Field" on gCCI...

    I spend few hours and i reall don't know how to make "Left Outer Join", please help!

    Thursday, December 6, 2012 3:15 PM

Answers

  • Hi wrk2;

    Please try the below query, I believe it will give you what you need.

    From rCZY As DataRow In tbCZY
    Join rCCI As DataRow In tbCCI
    On rCZY.Field(Of Int32)("ID_CZY") Equals rCCI.Field(Of Int32)("ID_CZY") Into gCCI = Group 
    From m In gCCI.DefaultIfEmpty
    Select New With
    {
        .ID_CZY = rCZY.Field(Of Int32)("ID_CZY"),
        .ID_CI = m.Field(Of Int32)("ID_CI")
    }

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by wrk2 Thursday, December 6, 2012 8:45 PM
    Thursday, December 6, 2012 8:21 PM

All replies

  • Hi wrk2;

    Please try the below query, I believe it will give you what you need.

    From rCZY As DataRow In tbCZY
    Join rCCI As DataRow In tbCCI
    On rCZY.Field(Of Int32)("ID_CZY") Equals rCCI.Field(Of Int32)("ID_CZY") Into gCCI = Group 
    From m In gCCI.DefaultIfEmpty
    Select New With
    {
        .ID_CZY = rCZY.Field(Of Int32)("ID_CZY"),
        .ID_CI = m.Field(Of Int32)("ID_CI")
    }

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by wrk2 Thursday, December 6, 2012 8:45 PM
    Thursday, December 6, 2012 8:21 PM
  • Hi Fernando!

    Thank You for answer!

    I added "Group" before "Join" in Your code (without this there was error near "Into"):

    Group Join rCCI As DataRow In tbCCI

    and now it looks good! :-)

    My mistake was using "gCCI.Field" instead of "m.Filed"

    Thursday, December 6, 2012 8:45 PM
  •  

    Not a problem, 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".

    Thursday, December 6, 2012 8:51 PM