请教linq查询问题?
有如下的数据表:
字段1字段2字段3字段4字段5字段6字段7字段8
TFTTFFFT
FFTFFTTF
TTTFFFFF
TFTFTFTF
TTTTTTTT
……
我想查询所有字段值都为T的记录,那么linq语句该怎么写,是要在where语句里面写“where 字段1=T and 字段2=T and……”这样么?
[解决办法]
- C# code
void Main(){ var queryResults = from c in dbContxt.customers let cloumns=dbContxt.ExecuteQuery<temp>("select name from syscolumns where id=object_id(N'customers')",""); where cloumns.All(d=>GetPropertyValue(c,d.name)=="T") select c; }public class temp{ public string name{get;set;}}private static object GetPropertyValue(object obj, string property) { System.Reflection.PropertyInfo propertyInfo=obj.GetType().GetProperty(property); return propertyInfo.GetValue(obj, null); }