public PageList <T> PageList(int pageIndex, int pageSize) { //查询总行数 SqlProvider.FormatCount(); var pageTotal = DbCon.QuerySingles <int>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction); //查询数据 SqlProvider.FormatToPageList <T>(pageIndex, pageSize); var itemList = DbCon.Query_1 <T>(SqlProvider.SqlString, SqlProvider.ProviderOption, SqlProvider.Params, DbTransaction); return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList)); }
public async Task <PageList <TReturn> > PageListAsync <TReturn>(int pageIndex, int pageSize, bool where, Expression <Func <T, TReturn> > trueSelect, Expression <Func <T, TReturn> > falseSelect) { if (where) { SqlProvider.Context.Set.SelectExpression = trueSelect; } else { SqlProvider.Context.Set.SelectExpression = falseSelect; } //查询总行数 SqlProvider.FormatCount(); var pageTotal = await DbCon.QuerySinglesAsync <int>(SqlProvider, DbTransaction); //查询数据 List <TReturn> itemList; SqlProvider.Params.Clear(); SqlProvider.ProviderOption.MappingList.Clear(); if (pageTotal != 0) { SqlProvider.FormatToPageList <T>(pageIndex, pageSize); itemList = await DbCon.Query_1Async <TReturn>(SqlProvider, DbTransaction); } else { itemList = new List <TReturn>(); } return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList)); }
public int Count() { SqlProvider.FormatCount(); SetSql(); var result = DbCon.QuerySingle <int>(SqlProvider.SqlString, SqlProvider.Params); return(result); }
public async Task <int> CountAsync() { SqlProvider.FormatCount(); SetSql(); var result = await DbCon.QuerySingleAsync <int>(SqlProvider.SqlString, SqlProvider.Params); return(result); }
public PageList <T> PageList(int pageIndex, int pageSize) { SqlProvider.FormatToPageList <T>(pageIndex, pageSize); using (var queryResult = DbCon.QueryMultiples <T>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction)) { //oracle不支持返回多条结果集 var pageTotal = 0; if (SqlProvider.IsSelectCount) { SqlProvider.FormatCount(); pageTotal = DbCon.QuerySingles <int>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction); } else { pageTotal = queryResult.ReadFirst <int>(); } var itemList = queryResult.Read <T>().ToList(); return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList)); } }
public PageList <TSource> PageList <TSource>(int pageIndex, int pageSize) { //查询总行数 SqlProvider.FormatCount(); var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction); SqlProvider.FormatToPageList <T>(pageIndex, pageSize); //查询数据 var itemList = DbCon.Query_1 <TSource>(SqlProvider, DbTransaction); return(new PageList <TSource>(pageIndex, pageSize, pageTotal, itemList)); }
public PageList <TReturn> PageList <TReturn>(int pageIndex, int pageSize, Expression <Func <T, TReturn> > select) { //查询总行数 SqlProvider.FormatCount(); var pageTotal = DbCon.QuerySingles <int>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction); //查询数据 SqlProvider.Context.Set.SelectExpression = select; SqlProvider.FormatToPageList <T>(pageIndex, pageSize); var itemList = DbCon.Query_1 <TReturn>(SqlProvider.SqlString, SqlProvider.ProviderOption, SqlProvider.Params, DbTransaction); return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList)); }
/// <summary> /// 反射执行需要指向T类型的函数 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sqlProvider"></param> /// <param name="methodName"></param> public void FormatSend <T>(SqlProvider sqlProvider, string methodName) { switch (methodName) { case "Count": { sqlProvider.FormatCount(); } break; case "Sum": { var lambda = this.expression.Arguments[0].GetLambdaExpression(); sqlProvider.FormatSum(lambda); } break; case "Get": { //加上自定义实体返回 var lambda = this.expression.Arguments[0].GetLambdaExpression(); this.ReturnType = lambda.ReturnType; sqlProvider.Context.Set.SelectExpression = lambda; sqlProvider.FormatGet <T>(); } break; case "ToList": { //加上自定义实体返回 var lambda = this.expression.Arguments[0].GetLambdaExpression(); this.ReturnType = lambda.ReturnType; sqlProvider.Context.Set.SelectExpression = lambda; sqlProvider.FormatToList <T>(); } break; default: throw new DapperExtensionException("the expression is no support this function"); } //得到解析的sql和param对象 string sql = sqlProvider.SqlString; var param = ToSubqueryParam(sqlProvider.Params, ref sql); _sqlCmd.Append(sql); this.Param.AddDynamicParams(param); }
public PageList <TReturn> PageList <TReturn>(int pageIndex, int pageSize, bool where, Expression <Func <T, TReturn> > trueSelect, Expression <Func <T, TReturn> > falseSelect) { //查询总行数 SqlProvider.FormatCount(); var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction); if (where) { SqlProvider.Context.Set.SelectExpression = trueSelect; } else { SqlProvider.Context.Set.SelectExpression = falseSelect; } SqlProvider.FormatToPageList <T>(pageIndex, pageSize); var itemList = DbCon.Query_1 <TReturn>(SqlProvider, DbTransaction); return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList)); }
public PageList <TSource> PageList <TSource>(int pageIndex, int pageSize) { //查询总行数 SqlProvider.FormatCount(); var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction); //查询数据 List <TSource> itemList; SqlProvider.Clear(); if (pageTotal != 0) { SqlProvider.FormatToPageList <T>(pageIndex, pageSize); itemList = DbCon.Query_1 <TSource>(SqlProvider, DbTransaction); } else { itemList = new List <TSource>(); } return(new PageList <TSource>(pageIndex, pageSize, pageTotal, itemList)); }
public async Task <PageList <T> > PageListAsync(int pageIndex, int pageSize) { //查询总行数 SqlProvider.FormatCount(); var pageTotal = await DbCon.QuerySinglesAsync <int>(SqlProvider, DbTransaction); //查询数据 List <T> itemList; SqlProvider.Clear(); if (pageTotal != 0) { SqlProvider.FormatToPageList <T>(pageIndex, pageSize); itemList = await DbCon.Query_1Async <T>(SqlProvider, DbTransaction); } else { itemList = new List <T>(); } return(new PageList <T>(pageIndex, pageSize, pageTotal, itemList)); }
public PageList <TReturn> PageList <TReturn>(int pageIndex, int pageSize, Expression <Func <T, TReturn> > select) { SqlProvider.Context.Set.SelectExpression = select; //查询总行数 SqlProvider.FormatCount(); var pageTotal = DbCon.QuerySingles <int>(SqlProvider, DbTransaction); //查询数据 List <TReturn> itemList; SqlProvider.Clear(); if (pageTotal != 0) { SqlProvider.FormatToPageList <T>(pageIndex, pageSize); itemList = DbCon.Query_1 <TReturn>(SqlProvider, DbTransaction); } else { itemList = new List <TReturn>(); } return(new PageList <TReturn>(pageIndex, pageSize, pageTotal, itemList)); }
public async Task <int> CountAsync() { SqlProvider.FormatCount(); SetSql(); return(await DbCon.ExecuteScalarAsync <int>(SqlProvider.SqlString, SqlProvider.Params)); }
/// <inheritdoc /> public int Count() { SqlProvider.FormatCount(); return(DbCon.QuerySingleOrDefault <int>(SqlProvider.SqlString, SqlProvider.Params, dbTransaction)); }
public int Count() { SqlProvider.FormatCount(); SetSql(); return(DbCon.ExecuteScalar <int>(SqlProvider.SqlString, SqlProvider.Params)); }
/// <summary> /// 反射执行需要指向T类型的函数 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sqlProvider"></param> /// <param name="methodName"></param> public void FormatSend <T>(QuerySet <T> querySet, string methodName) { SqlProvider sqlProvider = querySet.SqlProvider; //写入重新生成后的条件 if (WhereExpression != null && WhereExpression.Any()) { querySet.WhereExpressionList.AddRange(WhereExpression); } //因为表达式的原因,递归获取连表默认会倒序 if (sqlProvider.JoinList.Any()) { sqlProvider.JoinList.Reverse(); } switch (methodName) { case "Count": { sqlProvider.FormatCount(); } break; case "Sum": { var lambda = this.expression.Arguments[0].GetLambdaExpression(); sqlProvider.FormatSum(lambda); } break; case "Min": { var lambda = this.expression.Arguments[0].GetLambdaExpression(); sqlProvider.FormatMin(lambda); } break; case "Max": { var lambda = this.expression.Arguments[0].GetLambdaExpression(); sqlProvider.FormatMax(lambda); } break; case "Get": { LambdaExpression lambda = default(LambdaExpression); if (this.expression.Arguments.Count == 1) { lambda = this.expression.Arguments[0].GetLambdaExpression(); this.ReturnType = lambda.ReturnType; } else if (this.expression.Arguments.Count == 0) //无自定义列表返回 { lambda = null; this.ReturnType = this.expression.Method.ReturnType; } else { //带if判断 if (this.expression.Arguments[0].ToConvertAndGetValue().Equals(true)) { lambda = this.expression.Arguments[1].GetLambdaExpression(); } else { lambda = this.expression.Arguments[2].GetLambdaExpression(); } this.ReturnType = lambda.ReturnType; } sqlProvider.Context.Set.SelectExpression = lambda; sqlProvider.FormatGet <T>(); } break; case "ToList": { LambdaExpression lambda = default(LambdaExpression); if (this.expression.Arguments.Count == 1) { lambda = this.expression.Arguments[0].GetLambdaExpression(); this.ReturnType = lambda.ReturnType; } else if (this.expression.Arguments.Count == 0) //无自定义列表返回 { lambda = null; this.ReturnType = this.expression.Method.ReturnType.GenericTypeArguments[0]; } else { //带if判断 if (this.expression.Arguments[0].ToConvertAndGetValue().Equals(true)) { lambda = this.expression.Arguments[1].GetLambdaExpression(); } else { lambda = this.expression.Arguments[2].GetLambdaExpression(); } this.ReturnType = lambda.ReturnType; } sqlProvider.Context.Set.SelectExpression = lambda; sqlProvider.FormatToList <T>(); } break; default: throw new DapperExtensionException("Kogel.Dapper.Extension中子查询不支持的扩展函数"); } //得到解析的sql和param对象 string sql = sqlProvider.SqlString; var param = ToSubqueryParam(sqlProvider.Params, ref sql); _sqlCmd.Append(sql); this.Param.AddDynamicParams(param); }
public int Count() { SqlProvider.FormatCount(); return(DbCon.QuerySingle <int>(SqlProvider.SqlString, SqlProvider.Params)); }