Reputation: 129
I searched a lot, but couldn't find what I was looking exactly. This may be very simple. Normally in LINQ we write the select query like this:
var entityModel = new StudentEntities();
var dept = (from a in entityModel.STUDENT where a.NAME != null select a.DEPARTMENT).Distinct().OrderBy(w => w);
//STUDENT- table, NAME-column name, DEPARTMENT-column name
How to write the same query using dynamic LINQ? Here the table name and column name names will be selected from either some winForm controls (textbox/combobox) or string. Tried this:
var dept = "(from a in entityModel." + tableName + "where a." + cbo1.Text.ToString + "!= null select a."+cbo2.Text.ToString +").Distinct().OrderBy(w => w)";
This is not working. Can anyone point me to the right direction, please?
Upvotes: 0
Views: 654
Reputation: 5447
You can't do that. You need to generate your dynamic SQL and run it over your database.
There's this library: Dynamic LINQ, but it isn't as dynamic as you want.
Upvotes: 1