public static string GetWhereCondition(T t)
{
//构造查询条件
StringBuilder where = new StringBuilder(512);
Type type = typeof(T);
if (t == null)
return string.Empty;
PropertyInfo sortproperty = null;
string defaultorderby = string.Empty;
foreach (PropertyInfo item in type.GetProperties())
{
if (string.IsNullOrEmpty(defaultorderby))
{
defaultorderby = item.Name;
}
//字段为空不拼接入查询条件
if (item.GetValue(t, null) == null)
continue;
代码没有帖完吧,从名字上看是该方法的功能是,拼接SQL查询语句WHERE部分。
根据反射取出对象t中的属性拼接出查询条件,并设置默认排序方式,
运用的泛型构建的查询吧!