日期:2014-05-20  浏览次数:20992 次

请教linq查询问题?
有如下的数据表:
字段1 字段2 字段3 字段4 字段5 字段6 字段7 字段8
T F T T F F F T
F F T F F T T F
T T T F F F F F
T F T F T F T F
T T T T T T T T
……
我想查询所有字段值都为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);  
}