Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to do left and inner join in same query

How to do left and inner join in same query

Scheduled Pinned Locked Moved C#
csharpdatabaselinqdockertutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mou_kol
    wrote on last edited by
    #1

    See my linq query first

    var query = (from r1 in dtMappedSectionNotEmpty.AsEnumerable()
    join r2 in dtData.AsEnumerable()
    on r1.Field("Row").Trim().ToUpper() equals r2.Field("RowCoordinate").Trim().ToUpper()
    join r3 in _Periods.AsEnumerable()
    on r2.Field("StandardDate").Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper() equals r3.Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper()
    where r1.Field("Tab").Trim().ToUpper() == strTab.Trim().ToUpper()
    select new BrokerData
    {
    RowNumber = r1.Field("Row") ?? "0",
    TabName = r1.Field("Matched Section") ?? "",
    StandardDate = r3.ToString(),
    BRTab = r1.Field("Tab") ?? "",
    BRLineItem = r1.Field("Broker Items") ?? "",
    Action = r1.Field("Action") ?? "",
    StandardLineItem = r1.Field("Matched Items") ?? "",
    StandardValue =r2.Field("LineItemDateValue") ?? ""
    }).ToList();

    in my above code there are 2 datatable and one list. now i am not being able to compose left and inner join in same query. there will be left join between dtMappedSectionNotEmpty and dtData datatable. means left join between r1 & r2 again there will be inner join between dtData & _Periods means i want inner join between r2 & r3 so please see my code and give me another set same LINQ code where left join and inner join will be there in same query. thanks

    L 1 Reply Last reply
    0
    • M Mou_kol

      See my linq query first

      var query = (from r1 in dtMappedSectionNotEmpty.AsEnumerable()
      join r2 in dtData.AsEnumerable()
      on r1.Field("Row").Trim().ToUpper() equals r2.Field("RowCoordinate").Trim().ToUpper()
      join r3 in _Periods.AsEnumerable()
      on r2.Field("StandardDate").Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper() equals r3.Replace("A", string.Empty).Replace("E", string.Empty).Trim().ToUpper()
      where r1.Field("Tab").Trim().ToUpper() == strTab.Trim().ToUpper()
      select new BrokerData
      {
      RowNumber = r1.Field("Row") ?? "0",
      TabName = r1.Field("Matched Section") ?? "",
      StandardDate = r3.ToString(),
      BRTab = r1.Field("Tab") ?? "",
      BRLineItem = r1.Field("Broker Items") ?? "",
      Action = r1.Field("Action") ?? "",
      StandardLineItem = r1.Field("Matched Items") ?? "",
      StandardValue =r2.Field("LineItemDateValue") ?? ""
      }).ToList();

      in my above code there are 2 datatable and one list. now i am not being able to compose left and inner join in same query. there will be left join between dtMappedSectionNotEmpty and dtData datatable. means left join between r1 & r2 again there will be inner join between dtData & _Periods means i want inner join between r2 & r3 so please see my code and give me another set same LINQ code where left join and inner join will be there in same query. thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use "intermediate" queries. LINQ will do the same internally. There is nothing special or heroic in doing it in the "same query".

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      M 1 Reply Last reply
      0
      • L Lost User

        Use "intermediate" queries. LINQ will do the same internally. There is nothing special or heroic in doing it in the "same query".

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        M Offline
        M Offline
        Mou_kol
        wrote on last edited by
        #3

        i know i can break the query into two separate to achieve this job but i need to know if i want to do left & inner join in same query then how could i compose it. i stuck for syntax. if you know then post a sample LINQ query where left & inner join will be performed in same query. thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups