Reputation: 21
Sorry for my bad English. I have a problem. I want to create dynamic where
clause in a LINQ query. I have one list object name "list1" having values Country
, City
, State
and one datatable that has column named Name
, Lastname
, Country
, City
, State
. I want to compare list1 values with datatable columns and get null / empty rows.
So I want a LINQ query like this:
var query = from p in datatable.AsEnumerable()
where list1 == null
select p
but it returns an error. How can I solve this problem?
Thanks in advance.
Upvotes: 1
Views: 809
Reputation: 62157
Ok, let's get going - your query is ridiculously bad.
datatable.AsEnumerable
- that forces a table scan (running through the whole table).In general, every query is an IQueryable
itself, so you can chain where conditions.VERY nice - I use that partially myself, defining the core query, then adding additional where clauses as needed (by input parameter) before executing.
Sadly, comparing a table against a list of elements by individual field match is as bad as it gets from the sql level.
Upvotes: 1