I am trying to run some tests with Dynamic Linq at the moment, but being new to this, I am having problems.
Currently, I have one DataTable that I populated with an SQL query in the database. Now I want to execute dynamic linq queries in this DataTable. This may seem counterintuitive, but my ultimate goal is to perform joins on two different data tables that are populated with two different databases, so keeping that in mind, I hope this makes more sense. I am trying to understand a simpler situation and experiment a bit with it before I continue this main problem.
The question is, I'm not quite sure about the choice between IQueryable (Of T) and IEnumerable (Of T). I understand that if you do everything in memory, you choose IEnumerable. I would think that this is suitable for my business, right? However, when I looked at changing IEnumerable to IQuerbyable (in the code snippet below), I was surprised to see that "x.Item (Field Name)" does not work !? What am I missing? The error he gave was: "Late Binding operations cannot be converted to an Expression Tree."
Anyway, let's see. I already got some of the work:
Dim desc As String = "Description"
Dim status As String = "Status"
Dim query As IEnumerable(Of DataRow) = From x In tab.AsEnumerable()
query = query.Where(Function(x As Object) x.Item(status) < 100)
For Each row As DataRow In query.ToList()
'Do something
Next row
, . , , . , "x! " - . , .. . , :
query = query.Select(Of String)(Function(x As Object) x.Item(desc))
(N.B.: Select (Of String), . )
InvalidCastException: " " WhereSelectEnumerableIterator 2[System.Data.DataRow,System.String]' to type 'System.Collections.Generic.IEnumerable 1 [System.Data.DataRow] ". , ; , - , DataRow, , . - / ?
!
, , , , :
where select. , , , . , .Where() .Select(), IEnumerable.