I would like to do something like this:
DataTable q = from c in customers
join o in orders on c.Key equals o.Key
into outer
from j in outer.DefaultIfEmpty()
select new { c.*, j.* };
The closest I currently got is the following:
var q = from c in customers
join o in orders on c.Key equals o.Key
into outer
from j in outer.DefaultIfEmpty()
select new { c, j };
I'd like my result (q) to have all the columns from c and j. both c and j contain a lot of columns, so I'd rather not list them as such:
select new { c.col1, c.col2, etc. }
But I basically want the final DataTable to be made up of c.* and j.*.
This answer (not the accepted answer, but the one below it) works if I specify all the c and j columns inside 'select new': How to Convert a LINQ result to DATATABLE? But I'd like to avoid listing them all.
new { Customer = c, Order = j }. Note thatnew { c.col1 }is effectivelynew { col1 = c.col1 }by language-magic. Here is a question I asked about the particular syntax. - user166390Expression<Func<T1, T2, T3>>and use that expression as your select expression. How exactly you would do that, I don't know. - cadrell0new { c, .. }is effectively the same asnew { Customer = c, .. }- user166390