8,497
社区成员
发帖
与我相关
我的任务
分享
string Sqlw = " 1==1 ";
if (typeid > 0)
Sqlw = "&& result => result.Field<int>(\"typeid\")==" + typeid;
if (quest != "")
{
//这一段是我自作主张改的一个非空查询或者模糊查询的方法,
//quest是一个传参。如果为"name"或者"name|"就代表我这个name字段不能为空
//如果quest传过来为"name|123"就代表我要根据"123"来对name字段做模糊查询。
string[] arr = quest.Split('|');
if (arr.Length > 2)
{
if (arr[1] != "")
{
Sqlw = "&& result => result." + arr[0] + ".Contains('" + arr[1] + "')";
}
else
Sqlw = "&& result => result.Field<string>(\"" + arr[0] + "\")!= \"\"";
}
else
Sqlw = "&& result => result.Field<string>(\"" + arr[0] + "\")!= \"\"";
}
var x = from result in dt.AsEnumerable() where Sqlw select result;
var x = from result in dt.AsEnumerable() select result;
if (typeid > 0)
x = x.Where( result => result.Field<int>("typeid")== typeid);
if (quest != "")
{
string[] arr = quest.Split('|');
if (arr.Length > 2)
{
if (arr[1] != "")
{
x = x.Where( result => GetPropertyValue(result, arr[0] ).ToString().Contains( arr[1] +);
}
else
x = x.Where( result => GetPropertyValue(result, arr[0] ) != "";
}
else
x = x.Where( result => GetPropertyValue(result, arr[0] ) != "";
}
private static object GetPropertyValue(object obj, string property)
{
System.Reflection.PropertyInfo propertyInfo=obj.GetType().GetProperty(property);
return propertyInfo.GetValue(obj, null);
}
var q = from result in table where result.a == a select result
2.var q = table.Where(e=>e.a == a).Select()