none
How to create a UNION ALL on two tables in linq RRS feed

  • Question

  • How do I create a UNION ALL on two tables in linq.
    I cant find examples no where. Does linq not have a tool to change SQL to LINQ ?
    Thursday, October 30, 2008 2:30 PM

Answers

  • There is no tool that turns SQL into LINQ.  At least not one that I know of.

     

    You can do a UNION operation using the Union operator.  UNION ALL is equivalent to the Concat operator.  In order to use them, you'll have to project the data from each table into the same data type.

     

    var query = (from x in db.Table1 select new {A = x.A, B = x.B})

                     .Concat( from y in db.Table2 select new {A = y.A, B = y.B} );

     

     

     

     

     

    Thursday, October 30, 2008 3:10 PM
    Moderator

All replies

  • There is no tool that turns SQL into LINQ.  At least not one that I know of.

     

    You can do a UNION operation using the Union operator.  UNION ALL is equivalent to the Concat operator.  In order to use them, you'll have to project the data from each table into the same data type.

     

    var query = (from x in db.Table1 select new {A = x.A, B = x.B})

                     .Concat( from y in db.Table2 select new {A = y.A, B = y.B} );

     

     

     

     

     

    Thursday, October 30, 2008 3:10 PM
    Moderator
  • Actually there is one tool present named Linqer4Inst .After giving the connection string in the application it will automatically create the entities present in the data base.And then you can use it for your LINQ query.

    Tuesday, July 17, 2012 8:55 AM