Reputation: 71
How can i use dynamic columns on Linq?
For example;
var tmp = (from i in ESE.viw_kisiler
where (i.i_want_to_use_dynamic_column_in_here.Contains(kelime))
select i);
Other example;
var a = (ComboBoxItems)ComboBox1.SelectedItem;
var ColumnName = a.Value;
var tmp = (from i in ESE.viw_kisiler
where (i.ColumnName.Contains(kelime))
select i);
Thanks for all.
Upvotes: 1
Views: 2588
Reputation: 71
Thanks for your all replies and comments.
I use a different method;
var SQL1 = (from i in ESE.viw_kisiler
select i);
DataTable DT = LINQToDataTable(SQL1);
var SQL2 = (from t in DT.AsEnumerable()
where t.Field<string>(ColumnName).Contains(Word)
select t);
First of all i was convert Linq Query a DataTable and then i try this codes. It was working now!
Upvotes: 1
Reputation: 176896
Make use of dynamic linq library : Dynamic LINQ (Part 1: Using the LINQ Dynamic Query Library) or predicate builder
you can also check : Dynamic query with Linq article on blog.
Upvotes: 1