/// <summary> /// 目前只支持单字段 /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="tKey"></typeparam> /// <param name="selectInfo"></param> /// <param name="predicate"></param> /// <returns></returns> public static SelectInfo <T> OrderByDescending <T, tKey>(this SelectInfo <T> selectInfo, Expression <Func <T, tKey> > predicate) { Expression body = predicate.Body; MemberExpression m = (MemberExpression)body; PropertyInfo propertyInfo = m.Member as PropertyInfo; string orderByName = propertyInfo.Name; string orderByStr = " " + orderByName + " DESC "; //处理先后关系 selectInfo.orderByStr.Add(selectInfo.orderByStr.Count + 1, orderByStr); return(selectInfo); }
public static CheckInfo Check <T>(this SelectInfo <T> selectInfo, ref List <ErrorList> erolt) { List <ErrorList> erolts = new List <ErrorList>(); Dictionary <string, IConfigIO> retDic = new Dictionary <string, IConfigIO>(); CheckInfo checkInfo = new CheckInfo(); Type[] configIOList = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetCustomAttribute <ConfigIOAttr>() != null).ToArray(); foreach (Type type in configIOList) { Activator.CreateInstance(type.MakeGenericType(typeof(T)), selectInfo, erolts, checkInfo); } erolt = erolts; //检查错误 return(checkInfo); }
public Errorinfo Check03(SelectInfo <T> selectInfo, CheckInfo checkInfo) { Errorinfo errorinfo = new Errorinfo(); if (string.IsNullOrEmpty(selectInfo.strWhere)) { errorinfo.Warning = "strWhere is null"; checkInfo.strWhere = ""; } else { checkInfo.strWhere = selectInfo.strWhere; } return(errorinfo); }
public Errorinfo Check05(SelectInfo <T> selectInfo, CheckInfo checkInfo) { Errorinfo errorinfo = new Errorinfo(); if (selectInfo.recordNum == -1) { errorinfo.Warning = "recordNum is null,default is changed to 10"; checkInfo.recordNum = 10; } if (errorinfo.Calibration && string.IsNullOrEmpty(errorinfo.Warning)) { checkInfo.recordNum = selectInfo.recordNum; } return(errorinfo); }
public Errorinfo Check02(SelectInfo <T> selectInfo, CheckInfo checkInfo) { Errorinfo errorinfo = new Errorinfo(); if (selectInfo.tableType == -1) { errorinfo.Warning = "tableType is null,default is changed to Table"; checkInfo.tableType = TableType.Table; } if (errorinfo.Calibration && string.IsNullOrEmpty(errorinfo.Warning)) { checkInfo.tableType = selectInfo.tableType; } return(errorinfo); }
public Errorinfo Check01(SelectInfo <T> selectInfo, CheckInfo checkInfo) { Errorinfo errorinfo = new Errorinfo(); if (selectInfo.tableName == null) { errorinfo.Calibration = false; errorinfo.Error = "tableName is not null"; } if (errorinfo.Calibration) { checkInfo.tableName = selectInfo.tableName; } return(errorinfo); }
public Check(SelectInfo <T> selectInfo, List <ErrorList> erolt, CheckInfo checkInfo) { var methods = GetType().GetMethods().Where(t => t.GetCustomAttribute <ConfigMethodAttr>() != null); foreach (MethodInfo method in methods) { ErrorList errorList = new ErrorList(); string configName = method.GetCustomAttribute <ConfigMethodAttr>().Name.ToUpper(); Errorinfo errorinfo = method.Invoke(this, new object[] { selectInfo, checkInfo }) as Errorinfo; errorList.Name = configName; errorList.Errorinfo = errorinfo; if (!errorinfo.Calibration || !string.IsNullOrEmpty(errorinfo.Warning)) { erolt.Add(errorList); } } }
public Errorinfo Check06(SelectInfo <T> selectInfo, CheckInfo checkInfo) { Errorinfo errorinfo = new Errorinfo(); string orderByStr = string.Empty; if (selectInfo.orderByStr.ToList().Count == 0) { errorinfo.Warning = "orderByStr is null,default is changed to order by 1"; checkInfo.orderByStr = "order by 1"; } else { foreach (var item in selectInfo.orderByStr.ToList()) { orderByStr += "," + item.Value; } checkInfo.orderByStr = orderByStr; } return(errorinfo); }
/// <summary> /// 分页 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="selectInfo"></param> /// <param name="pageNum"></param> /// <param name="recordNum"></param> /// <returns></returns> public static SelectInfo <T> SetPaging <T>(this SelectInfo <T> selectInfo, int pageNum, int recordNum = 0) { selectInfo.pageNum = pageNum; selectInfo.recordNum = recordNum; return(selectInfo); }
/// <summary> /// 设置查询类型:TableType.Table/View /// </summary> /// <typeparam name="T"></typeparam> /// <param name="selectInfo"></param> /// <param name="tableType"></param> /// <returns></returns> public static SelectInfo <T> SetType <T>(this SelectInfo <T> selectInfo, int tableType) { selectInfo.tableType = tableType; return(selectInfo); }
/// <summary> /// Where语句:EF,DataBaseType.SqlServer, DataDeleteFlag.IsDelete /// </summary> /// <typeparam name="T"></typeparam> /// <param name="selectInfo"></param> /// <param name="predicate">Lambda</param> /// <param name="databaseType">数据库类型</param> /// <param name="IsDeleteFlag">是否开启删除标识</param> /// <returns></returns> public static SelectInfo <T> SetWhere <T>(this SelectInfo <T> selectInfo, Expression <Func <T, bool> > predicate, string databaseType, int IsDeleteFlag) { selectInfo.strWhere = SqlSugor.GetWhereStr <T>(predicate, DataBaseType.SqlServer, IsDeleteFlag == 1); return(selectInfo); }
public static GetByIdModel GetById <T>(this SelectInfo <T> selectInfo, string id) { GetByIdModel GetByIdModel = new GetByIdModel(); return(GetByIdModel); }
/// <summary> /// 是否转换成json返回 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="selectInfo"></param> /// <param name="jsonFlag"></param> /// <returns></returns> public static SelectInfo <T> ToJson <T>(this SelectInfo <T> selectInfo, bool jsonFlag) { selectInfo.jsonFlag = jsonFlag; return(selectInfo); }
public Errorinfo Check07(SelectInfo <T> selectInfo, CheckInfo checkInfo) { Errorinfo errorinfo = new Errorinfo(); return(errorinfo); }