コード例 #1
0
        public async Task <List <T> > ToListAsync()
        {
            SqlProvider.FormatToList <T>();
            var iEnumerable = await DbCon.QueryAsyncs <T>(SqlProvider, DbTransaction);

            return(iEnumerable.ToList());
        }
コード例 #2
0
 public List <TReturn> ToList <TReturn>(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.FormatToList <T>();
     return(DbCon.Query_1 <TReturn>(SqlProvider.SqlString, SqlProvider.ProviderOption, SqlProvider.Params, DbTransaction));
 }
コード例 #3
0
 public async Task <List <TReturn> > ToListAsync <TReturn>(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.FormatToList <T>();
     return(await DbCon.Query_1Async <TReturn>(SqlProvider, DbTransaction));
 }
コード例 #4
0
 public DataSet ToDataSet <TReturn>(bool where, Expression <Func <T, TReturn> > trueSelect, Expression <Func <T, TReturn> > falseSelect, IDbDataAdapter dataAdapter = null)
 {
     if (where)
     {
         SqlProvider.Context.Set.SelectExpression = trueSelect;
     }
     else
     {
         SqlProvider.Context.Set.SelectExpression = falseSelect;
     }
     SqlProvider.FormatToList <T>();
     return(DbCon.QueryDataSets(SqlProvider, DbTransaction, dataAdapter));
 }
コード例 #5
0
 public IEnumerable <TReturn> ToIEnumerable <TReturn>(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.FormatToList <T>();
     return(DbCon.Query_1 <TReturn>(SqlProvider, DbTransaction));
 }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
 public IEnumerable <TReturn> ToIEnumerable <TReturn>(Expression <Func <T, TReturn> > select)
 {
     SqlProvider.Context.Set.SelectExpression = select;
     SqlProvider.FormatToList <T>();
     return(DbCon.Query_1 <TReturn>(SqlProvider, DbTransaction));
 }
コード例 #8
0
 public async Task <DataSet> ToDataSetAsync(IDbDataAdapter dataAdapter = null)
 {
     SqlProvider.FormatToList <T>();
     return(await DbCon.QueryDataSetsAsync(SqlProvider, DbTransaction, dataAdapter));
 }
コード例 #9
0
        public List <T> ToList()
        {
            SqlProvider.FormatToList();

            return(DbCon.Query <T>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction).ToList());
        }
コード例 #10
0
 public IEnumerable <TSource> ToIEnumerable <TSource>()
 {
     SqlProvider.FormatToList <T>();
     return(DbCon.Querys <TSource>(SqlProvider, DbTransaction));
 }
コード例 #11
0
 public DataSet ToDataSet(IDbDataAdapter dataAdapter = null)
 {
     SqlProvider.FormatToList <T>();
     return(DbCon.QueryDataSets(SqlProvider, DbTransaction, dataAdapter));
 }
コード例 #12
0
 public DataSet ToDataSet <TReturn>(Expression <Func <T, TReturn> > select, IDbDataAdapter dataAdapter = null)
 {
     SqlProvider.Context.Set.SelectExpression = select;
     SqlProvider.FormatToList <T>();
     return(DbCon.QueryDataSets(SqlProvider, DbTransaction, dataAdapter));
 }
コード例 #13
0
 public List <TSource> ToList <TSource>()
 {
     SqlProvider.FormatToList <T>();
     return(DbCon.Querys <TSource>(SqlProvider, DbTransaction).ToList());
 }
コード例 #14
0
ファイル: Query.cs プロジェクト: Nilker/Account
 public virtual List <T> ToList()
 {
     SqlProvider.FormatToList(null, this.FieldAnyExpression);
     SetSql();
     return(Qr(SqlProvider.SqlString, SqlProvider.Params, DbTransaction).ToList());
 }
コード例 #15
0
        /// <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);
        }
コード例 #16
0
 public IEnumerable <T> ToIEnumerable()
 {
     SqlProvider.FormatToList <T>();
     return(DbCon.Querys <T>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction, SqlProvider.ProviderOption));
 }
コード例 #17
0
        public async Task <IEnumerable <T> > ToListAsync()
        {
            SqlProvider.FormatToList <T>();

            return(await DbCon.QueryAsync <T>(SqlProvider.SqlString, SqlProvider.Params, DbTransaction));
        }
コード例 #18
0
 public async Task <List <TReturn> > ToListAsync <TReturn>(Expression <Func <T, TReturn> > select)
 {
     SqlProvider.Context.Set.SelectExpression = select;
     SqlProvider.FormatToList <T>();
     return(await DbCon.Query_1Async <TReturn>(SqlProvider, DbTransaction));
 }
コード例 #19
0
 public async Task <List <TSource> > ToListAsync <TSource>()
 {
     SqlProvider.FormatToList <T>();
     return((await DbCon.QueryAsyncs <TSource>(SqlProvider, DbTransaction)).ToList());
 }
コード例 #20
0
 public async Task <IEnumerable <T> > ToIEnumerableAsync()
 {
     SqlProvider.FormatToList <T>();
     return(await DbCon.QueryAsyncs <T>(SqlProvider, DbTransaction));
 }
コード例 #21
0
 public List <TReturn> ToList <TReturn>(Expression <Func <T, TReturn> > select)
 {
     SqlProvider.Context.Set.SelectExpression = select;
     SqlProvider.FormatToList <T>();
     return(DbCon.Query_1 <TReturn>(SqlProvider.SqlString, SqlProvider.ProviderOption, SqlProvider.Params, DbTransaction));
 }