Reputation: 1007
So, I'm using LINQ in ASP.NET 4.0 to access my DB.
I have the following line of code:
var h = (from p in DB.d_tblDrinks where p.drinkID == _drinkID && p.drinkShow select p).First();
But i would like to access the property (eg. drinkID) with a variable, so i did this:
string prop = "drinkID";
var h = (from p in DB.d_tblDrinks where p.prop == _drinkID && p.drinkShow select p).First();
This is not possible, but is there some/similar way that makes it possible?
Thanks in advance!
Upvotes: 1
Views: 67
Reputation: 18770
Check out this Dynamic Linq Article.
You can download the LINQ Dynamic Query Library there and view a number of examples.
Then you can write completely dynamic LINQ queries.
Upvotes: 2