Exemple #1
0
        public static List <T> PageList <T, T1, T2, T3, T4>(this SqlConnection conn,
                                                            string table,
                                                            string fields,
                                                            Func <T, T1, T2, T3, T4, T> func,
                                                            ConditionBuilder condition,
                                                            SortBuilder sort,
                                                            int pageIndex, int pageSize, out int totalCount, SqlTransaction trans = null)
        {
            condition = condition ?? ConditionBuilder.New();
            sort      = sort ?? new SortBuilder();

            var sql = SqlServerSqlBuilder.PagingSelectWithTotalCount(table, fields, condition.ToCondition(), sort.ToOrderBy(),
                                                                     pageIndex, pageSize);

            var parameters = condition.ToParameters();

            parameters.Add("RecordCount", dbType: DbType.Int32, direction: ParameterDirection.Output);

            var data = conn.Query(sql, func, parameters);

            totalCount = parameters.Get <int>("RecordCount");
            return(data.ToList());
        }
Exemple #2
0
        public static List <T> PageList <T>(this SqlConnection conn, ConditionBuilder condition, SortBuilder sort,
                                            int pageIndex, int pageSize, out int totalCount, SqlTransaction trans = null)
        {
            condition = condition ?? ConditionBuilder.New();
            sort      = sort ?? new SortBuilder();

            var info = EntityInfoContainer.Get(typeof(T));

            if (info.IsSoftDelete)
            {
                condition = condition.AndEqual("IsDel", false);
            }

            var sql = SqlServerSqlBuilder.PagingSelectWithTotalCount(info, condition.ToCondition(), sort.ToOrderBy(),
                                                                     pageIndex, pageSize);

            var parameters = condition.ToParameters();

            parameters.Add("RecordCount", dbType: DbType.Int32, direction: ParameterDirection.Output);

            var data = conn.Query <T>(sql, parameters, trans);

            totalCount = parameters.Get <int>("RecordCount");
            return(data.ToList());
        }
Exemple #3
0
        public static List <T> Fetch <T, T1, T2, T3, T4>(this SqlConnection conn,
                                                         string table,
                                                         string fields,
                                                         Func <T, T1, T2, T3, T4, T> func,
                                                         ConditionBuilder condition,
                                                         SortBuilder sort, SqlTransaction trans = null)
        {
            condition = condition ?? ConditionBuilder.New();
            sort      = sort ?? new SortBuilder();

            var sql = $"SELECT {fields} FROM [{table}] WHERE {condition.ToCondition()} ORDER BY {sort.ToOrderBy()}";

            return(conn.Query(sql, func, condition.ToParameters(), trans).ToList());
        }
Exemple #4
0
        public static List <T> Fetch <T>(this SqlConnection conn,
                                         ConditionBuilder condition,
                                         SortBuilder sort,
                                         SqlTransaction trans = null)
        {
            condition = condition ?? ConditionBuilder.New();
            sort      = sort ?? new SortBuilder();

            var info = EntityInfoContainer.Get(typeof(T));

            if (info.IsSoftDelete)
            {
                condition = condition.AndEqual("IsDel", false);
            }

            var sql = $"SELECT {info.GetSelectFields()} FROM [{info.TableName}] WHERE {condition.ToCondition()} ORDER BY {sort.ToOrderBy()}";

            return(conn.Query <T>(sql, condition.ToParameters(), trans).ToList());
        }
Exemple #5
0
        public static T FirstOrDefault <T, T1, T2, T3, T4, TPrimaryKey>(
            this SqlConnection conn,
            string table,
            string fields,
            Func <T, T1, T2, T3, T4, T> func,
            ConditionBuilder condition,
            SortBuilder sort,
            SqlTransaction trans = null)
            where T : IBaseEntity <TPrimaryKey>
        {
            condition = condition ?? ConditionBuilder.New();
            sort      = sort ?? new SortBuilder();

            var sql = SqlServerSqlBuilder.LoadByCondition(table, fields, condition.ToCondition(), sort.ToOrderBy());

            return(conn.Query(sql, func, condition.ToParameters(), trans).FirstOrDefault());
        }
Exemple #6
0
        public static T FirstOrDefault <T, TPrimaryKey>(this SqlConnection conn,
                                                        ConditionBuilder condition,
                                                        SortBuilder sort,
                                                        SqlTransaction trans = null)
            where T : IBaseEntity <TPrimaryKey>
        {
            condition = condition ?? ConditionBuilder.New();
            sort      = sort ?? new SortBuilder();

            var info = EntityInfoContainer.Get(typeof(T));

            if (info.IsSoftDelete)
            {
                condition = condition.AndEqual("IsDel", false);
            }

            var sql = SqlServerSqlBuilder.LoadByCondition(info, condition.ToCondition(), sort.ToOrderBy());

            return(conn.QueryFirstOrDefault <T>(sql, condition.ToParameters()));
        }