コード例 #1
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());
        }
コード例 #2
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());
        }
コード例 #3
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()));
        }