/// <summary> /// 获取最小值 /// </summary> /// <typeparam name="TResult"></typeparam> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <param name="minField">列</param> /// <returns></returns> public static object Min <T>(this Queryable <T> queryable, Expression <Func <T, object> > expression) { ResolveExpress re = new ResolveExpress(); var minField = re.GetExpressionRightField(expression); return(Min <T, object>(queryable, minField)); }
/// <summary> /// 条件筛选 例如:expression 为 it=>it.a inValues值为 new list《string》{"a" ,"b"} 生成的SQL就是 a in('a','b') /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <param name="expression"></param> /// <returns></returns> public static Queryable <T> In <T, FieldType>(this Queryable <T> queryable, Expression <Func <T, object> > expression, List <FieldType> inValues) { ResolveExpress re = new ResolveExpress(); var InFieldName = re.GetExpressionRightField(expression); return(In <T, FieldType>(queryable, InFieldName, inValues)); }
/// <summary> /// 分组 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <param name="expression">分组字段 it=>it.fieldName</param> /// <returns></returns> public static Queryable <T> GroupBy <T>(this Queryable <T> queryable, Expression <Func <T, object> > expression) { ResolveExpress re = new ResolveExpress(); var field = re.GetExpressionRightField(expression); var pre = queryable.GroupBy.IsValuable() ? "," : ""; queryable.GroupBy += pre + field; return(queryable); }
/// <summary> /// 排序 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="queryable"></param> /// <param name="expression">排序字段 it=>it.fieldName </param> /// <param name="type">排序类型</param> /// <returns></returns> public static Queryable <T> OrderBy <T>(this Queryable <T> queryable, Expression <Func <T, object> > expression, OrderByType type = OrderByType.asc) { ResolveExpress re = new ResolveExpress(); var field = re.GetExpressionRightField(expression); var pre = queryable.OrderBy.IsValuable() ? "," : ""; queryable.OrderBy += pre + field + " " + type.ToString().ToUpper(); return(queryable); }
/// <summary> /// 批量删除 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="FiledType">whereIn里面元素的类型</typeparam> /// <param name="expression">in 的字段名称</param> /// <param name="whereIn">需要删除条件值的数组集合</param> /// <returns></returns> public bool Delete <T, FiledType>(Expression <Func <T, object> > expression, params FiledType[] whereIn) { ResolveExpress re = new ResolveExpress(); var fieldName = re.GetExpressionRightField(expression); Type type = typeof(T); string typeName = type.Name; typeName = GetTableNameByClassType(typeName); //属性缓存 string cachePropertiesKey = "db." + type.FullName + ".GetProperties"; var cachePropertiesManager = CacheManager <PropertyInfo[]> .GetInstance(); PropertyInfo[] props = SqlSugarTool.GetGetPropertiesByCache(type, cachePropertiesKey, cachePropertiesManager); bool isSuccess = false; if (whereIn != null && whereIn.Length > 0) { string sql = string.Format("DELETE FROM {0} WHERE {1} IN ({2})", typeName, fieldName, whereIn.ToJoinSqlInVal()); int deleteRowCount = ExecuteCommand(sql); isSuccess = deleteRowCount > 0; } return(isSuccess); }