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. LINQ
  4. Linq solution to union two select statements

Linq solution to union two select statements

Scheduled Pinned Locked Moved LINQ
csharpdatabaselinqtoolstutorial
2 Posts 2 Posters 6 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.
  • D Offline
    D Offline
    duanepfeiffer
    wrote on last edited by
    #1

    I just discovered how to do this and thought I'd share it as I couldn't find it with google search for 'linq union' I wanted to reproduce the following SQL script using linq. select a, b, c from table1 union select a, b, c from table2 to do this in linq: var mainQuery = (from t1 in context.table1 select t1).AsEnumerable().Union(from t2 in context.table2 select t2).AsEnumerable(); :)

    P 1 Reply Last reply
    0
    • D duanepfeiffer

      I just discovered how to do this and thought I'd share it as I couldn't find it with google search for 'linq union' I wanted to reproduce the following SQL script using linq. select a, b, c from table1 union select a, b, c from table2 to do this in linq: var mainQuery = (from t1 in context.table1 select t1).AsEnumerable().Union(from t2 in context.table2 select t2).AsEnumerable(); :)

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Very nice, but you should probably add this as a tip or trick.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      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