I
I
iluxa18102016-03-20 02:06:15
Database
iluxa1810, 2016-03-20 02:06:15

Linq.Dynamic and DataTable?

Has anyone worked with the LINQ dynamic library?
How, having 2 DataTables, to make an INNER JOIN ?
I'm trying to do it this way:
C# Select code
var res2 = newDT.AsEnumerable().AsQueryable().Join(oldDT.AsEnumerable(), "new (@0 as T1)",
"new (@0 as T2)",
"new (T2 as Alias)", new object[] { "t2" } );
but an error occurs:
Additional information: Unknown identifier 'T2'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2016-03-20
@dmitryKovalskiy

Try using SQL like syntax. Perhaps it will become clearer that how JOIN is

var temp = from t in A
                  join b in B on t.Site = b.Site AND t.C = b.C
                  where condition
                  select what you need

Collections are marked with capital letters, alias are marked with small letters.

E
eRKa, 2016-03-20
@kttotto

At the request formation stage, you do not have the T2 object. There is a difference between Enumerable and Queryable. The Enumerable type - LINQ will execute as a pipeline, executing each extension in a chain. And Queryable will take all the chains at once and will try to form one SQL query. Therefore, your conversion .AsEnumerable().AsQueryable() is not entirely clear to me because I understand that DT initially returns a Queryable.
Basically, do this "new (@0 as T2)" somewhere before your join.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question