How to choose programaticaly the column to be queried by Linq using PropertyInfo???
- by Richard77
Hello,
I would like to control how linq querries my database programaticaly. For instance, I'd like to query the column X, column Y, or column Z, depending on some conditions.
First of all, I've created an array of all the properties inside my class called myPropertyInfo.
Type MyType = (typeOf(MyClass));
PropertyInfo[] myPropertyInfo = myType.GetProperties(
BindingFlags.Public|BindingFlags.Instance);
The myPropertyInfo array allows me to access each property details (Name, propertyType, etc) through the index*[i]*
Now, how can I use the above information to control how linq queries my DB?
Here's a sample of a querry I'd like to exploit.
var myVar = from tp in db.MyClass
select tp.{expression};
Expression using myPropertyInfo[i] to choose which property(column) to query.
I'm not sure if that's the way of doing it, but if there's another way to do so, I'll be glad to learn.
Thanks for helping.