How to choose programaticaly the column to be querried by Linq using PropertyInfo???
Posted
by Richard77
on Stack Overflow
See other posts from Stack Overflow
or by Richard77
Published on 2010-03-27T20:14:15Z
Indexed on
2010/03/27
20:23 UTC
Read the original article
Hit count: 172
Hello,
I would like to control how linq querries my database programaticaly. For instance, I'd like to querry 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 querries 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 querry.
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.
© Stack Overflow or respective owner