Beispiel #1
0
        public static List <T> GetList <T>(QueryInfo <T> model)
        {
            var getModel = model.GetModel;
            var list     = new List <T>();

            using (var db = new DbBuilder(model.Config))
            {
                var reader = db.GetDataReader(model.SqlString, model.Parameters);
                if (getModel != null)
                {
                    while (reader.Read())
                    {
                        list.Add(getModel(reader));
                    }
                }
                else
                {
                    var builder = EntityBuilder <T> .CreateBuilder(reader);

                    while (reader.Read())
                    {
                        list.Add(builder.Build(reader));
                    }
                }
            }
            return(list);
        }
Beispiel #2
0
        public static List <T> GetList <T>(PageInfo <T> model)
        {
            if (string.IsNullOrWhiteSpace(model.StrSelect))
            {
                model.StrSelect = "*";
            }
            if (model.Config == null)
            {
                throw new Exception("Config不能为空!");
            }
            if (string.IsNullOrWhiteSpace(model.StrFrom))
            {
                throw new Exception("StrFrom不能为空!");
            }
            if (string.IsNullOrWhiteSpace(model.StrOrder))
            {
                throw new Exception("StrOrder不能为空!");
            }

            var getModel = model.GetModel;
            var list     = new List <T>();

            using (var db = new DbBuilder(model.Config))
            {
                string sql         = "select count(1) as tcount from (" + model.StrFrom + ") where 1=1 " + model.StrWhere;
                var    recordCount = (int)new DbBuilder(model.Config).GetSingle(sql, model.Parameters);
                sql = SqlHelper.GetSqlString(model.StrFrom, model.PageSize, model.PageIndex, recordCount, "*", model.StrWhere, model.StrOrder, model.Config);
                var reader = db.GetDataReader(sql, model.Parameters);
                if (getModel != null)
                {
                    while (reader.Read())
                    {
                        list.Add(getModel(reader));
                    }
                }
                else
                {
                    var builder = EntityBuilder <T> .CreateBuilder(reader);

                    while (reader.Read())
                    {
                        list.Add(builder.Build(reader));
                    }
                }
            }
            return(list);
        }