Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select All columns for all tables in join + linq join

How to select all columns from tables in join using linq

Sql:

select CTRL_RUN_JOB.*, CTRL_DATA_STREAM.*  from CTRL_RUN_JOB inner join CTRL_DATA_STREAM       on CTRL_RUN_JOB.DATA_STREAM_ID= CTRL_DATA_STREAM.DATA_STREAM_ID 

Linq:

from CTLJCRJOB in CTRL_RUN_JOBs  join CTLRFDSTM in CTRL_DATA_STREAMs  on CTLJCRJOB.DATA_STREAM_ID equals CTLRFDSTM.DATA_STREAM_ID select  new {          CTLJCRJOB.*  // ???         ,CTLRFDSTM.*  // ??? } 

Thanks

like image 811
Sreedhar Avatar asked Nov 04 '09 05:11

Sreedhar


2 Answers

While you cant expand them to columns, you can simply return the entities. Eg:

select new { CTLJCRJOB, CTLRFDSTM } 

If you need it flattened, then you will have to write out the mapping yourself, but will still be very trivial.

like image 166
leppie Avatar answered Oct 07 '22 17:10

leppie


You could use the into clause, but it will not flatten it for you.

from CTLJCRJOB in CTRL_RUN_JOBs  join CTLRFDSTM in CTRL_DATA_STREAMs  on CTLJCRJOB.DATA_STREAM_ID equals CTLRFDSTM.DATA_STREAM_ID into ALLCOLUMNS from entry in ALLCOLUMNS select entry  
like image 31
gxtaillon Avatar answered Oct 07 '22 16:10

gxtaillon