Exemple #1
0
        public IList <T> GetList <T>(string sql, params object[] paramList)
            where T : new()
        {
            var dt = _dbAccess.GetDataTableBySQL(sql, paramList);

            return(ORMHelper.DataTableToList <T>(dt));
        }
Exemple #2
0
        /// <summary>
        /// 根据表达式,查询对象集合
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="criteria">表达式</param>
        /// <param name="orderBy">排序</param>
        /// <returns>指定类型的数据集合</returns>
        public IList <T> GetList <T>(Criteria criteria, params SortInfo[] orderBy)
            where T : new()
        {
            PreconditionAssert.IsNotNull(criteria, ErrorMessages.NullReferenceException);

            SelectCommandCreator dbCommandCreator = new SelectCommandCreator(_dbAccess);

            dbCommandCreator.OrderBy    = orderBy;
            dbCommandCreator.ObjectType = typeof(T);
            dbCommandCreator.Cri        = criteria;
            dbCommandCreator.SelectType = SelectType.GetListByExpression;
            DbCommand dbCommand = dbCommandCreator.GetDbCommand();
            DataTable dt        = _dbAccess.GetDataTableByCommand(dbCommand);

            return(ORMHelper.DataTableToList <T>(dt));
        }
Exemple #3
0
        /// <summary>
        /// 获取数据表中的所有数据集合,并按指定排序方式进行排序
        /// </summary>
        /// <typeparam name="T">指定的类型</typeparam>
        /// <param name="orderBy">排序方式</param>
        /// <returns>数据表中的所有数据集合</returns>
        /// 前置条件
        /// 传入的orderBy对象可以为空,为空的时候则不进行排序
        public IList <T> GetAll <T>(params SortInfo[] orderBy) where T : new()
        {
            PreconditionAssert.IsNotNull(orderBy, ErrorMessages.NullReferenceException);
            ORMHelper.EntityIsMappingDatabase(typeof(T), ErrorMessages.EntityMappingError);

            SelectCommandCreator dbCommandCreator = new SelectCommandCreator(_dbAccess);

            dbCommandCreator.ObjectType = typeof(T);
            dbCommandCreator.OrderBy    = orderBy;
            dbCommandCreator.SelectType = SelectType.GetAll;
            DbCommand dbCommand = dbCommandCreator.GetDbCommand();

            DataTable dt = _dbAccess.GetDataTableByCommand(dbCommand);

            return(ORMHelper.DataTableToList <T>(dt));
        }
Exemple #4
0
        /// <summary>
        /// 通过指定类型,过滤条件和排序方式从数据库中获取该指定类型的数据集合
        /// </summary>
        /// <typeparam name="T">指定类型</typeparam>
        /// <param name="entity">实体对象</param>
        /// <param name="filterProterties">字段名称,可包含多个</param>
        /// <param name="orderBy">排序方式</param>
        /// <returns>指定类型的数据集合</returns>
        /// 前置条件
        /// 传入的参数entity,filterProterties不允许为空
        /// orderBy可以为空,如果为空则不进行排序
        public IList <T> GetList <T>(T entity, string[] filterProterties, params SortInfo[] orderBy)
            where T : new()
        {
            //断言传入的entity对象为null或者为空字符串,出现空引用异常
            PreconditionAssert.IsNotNull(entity, ErrorMessages.NullReferenceException);
            PreconditionAssert.IsNotNull(filterProterties, ErrorMessages.NullReferenceException);
            ORMHelper.EntityIsMappingDatabase(entity.GetType(), ErrorMessages.EntityMappingError);

            SelectCommandCreator dbCommandCreator = new SelectCommandCreator(_dbAccess);

            dbCommandCreator.Entity           = entity;
            dbCommandCreator.FilterProterties = filterProterties;
            dbCommandCreator.OrderBy          = orderBy;
            dbCommandCreator.SelectType       = SelectType.GetList;
            DbCommand dbCommand = dbCommandCreator.GetDbCommand();
            DataTable dt        = _dbAccess.GetDataTableByCommand(dbCommand);

            return(ORMHelper.DataTableToList <T>(dt));
        }