Exemplo n.º 1
0
        public override int PagingByList(IList <T> entitys, IPaing paing, IWhereGroup wheres, IList <ISorting> sortin = null, IList <IProperty> disabled = null)
        {
            object rownum, s = null;

            if (wheres != null)
            {
                var d     = new DynamicHandlerCompiler <object>();
                var itmes = wheres.GetCreaterDynamicClassPropertys();
                var type  = d.CreaterAnonEntity("anonClass", itmes);
                s = Activator.CreateInstance(type, CreaterDynamicClassProperty.GetValues(itmes));
            }
            this.BatBuilder.SelectBatBuilder(wheres, new Polymerize[] { new Polymerize(this.Mapper.PrimaryKey, PolymerizeType.Count, "a") });
            this.ExecuteScalar(s, out rownum);
            paing.SetCount((int)rownum);
            if (paing.PageNum > 1)
            {
                var p = SqlDBbatBuilder <T> .FilterProperty(this.Mapper, disabled);

                sortin = SqlDBbatBuilder <T> .InitiSorting(this.Mapper, sortin);

                var str = new StringBuilder($"select  * from  ");
                str.Append($"(select  top({paing.PageNumber * paing.Showline})  {string.Join(",", p)}, row_number() over(order by {string.Join(",", sortin)} ) as row  from {this.Mapper.TableName}    ");
                str.Append($"{(wheres == null ? string.Empty : wheres.ToString())}) as paging ");
                str.Append($"where row>{paing.Showline * (paing.PageNumber - 1)}");
                var bar = new SqlDBbatBuilder <T>(this.Mapper);
                bar.Additional(str.ToString(), wheres);
                this.Execute(entitys, bar, s);
            }
            else
            {
                this.Select(entitys, wheres, disabled, sortin);
            }
            return(paing.Count);
        }
Exemplo n.º 2
0
        public override void UpdateBatBuilder(IWhereGroup where, IList <IProperty> disabled = null)
        {
            var propertys = SqlDBbatBuilder <T> .FilterUpdateProperty(_mapper, disabled);

            this._sqltext = new StringBuilder();
            this._sqltext.Append($"update {this._mapper.TableName} set {string.Join(",", propertys)}  {(where == null ? string.Empty : where.ToString())}");
            this.where = where;
        }
Exemplo n.º 3
0
        public override void InsertBatBuilder(IList <IProperty> disabled = null)
        {
            this._propertys = SqlDBbatBuilder <T> .FilterProperty(_mapper, disabled);

            this._sqltext = new StringBuilder();
            this._sqltext.Append($"insert into {this._mapper.TableName}");
            this._sqltext.Append($"({string.Join(",", this._propertys)}) values");
            this._sqltext.AppendLine($"({string.Join(",", CreaterParamersByName(this._propertys))})");
        }
Exemplo n.º 4
0
        public override void SelectBatBuilder(IWhereGroup where, int num, IEnumerable <Polymerize> polymerizes, IList <ISorting> sortin, IList <IProperty> disabled)
        {
            string polymerizeText;

            sortin          = InitiSorting(this._mapper, sortin);
            this._propertys = SqlDBbatBuilder <T> .FilterProperty(_mapper, polymerizes, disabled ?? new List <IProperty>(), out polymerizeText);

            this._sqltext = new StringBuilder();
            this._sqltext.Append($"select  {(num > 0 ? $" top({num})" : string.Empty) } {polymerizeText} {string.Join(",", this._propertys)} ");
            this._sqltext.Append($"from {this._mapper.TableName} {(where == null ? string.Empty : where.ToString())}");
            this._sqltext.Append(sortin == null ? string.Empty : $" order by {string.Join(",", sortin)} ");
            this._sqltext.Append(polymerizes == null ? string.Empty : $" group by {string.Join(",", this._propertys)} ");
            this.where = where;
        }
Exemplo n.º 5
0
        public override int PagingByList <K>(IList <T> entitys, IWhereGroup wheres, IPaing paing, JoinType Type, IList <ISorting> sortin = null, IList <IProperty> disabled = null)

        {
            object rownum, s = null;

            if (wheres != null)
            {
                var d     = new DynamicHandlerCompiler <object>();
                var itmes = wheres.GetCreaterDynamicClassPropertys();
                var type  = d.CreaterAnonEntity("anonClass", itmes);
                s = Activator.CreateInstance(type, CreaterDynamicClassProperty.GetValues(itmes));
            }
            this.BatBuilder.ScalarBatBuilder <K>(wheres, -1, Type, new Polymerize[] { new Polymerize(this.Mapper.PrimaryKey, PolymerizeType.Count, "a", this.Mapper.TableName) }, null, null);
            this.ExecuteScalar(s, out rownum);
            paing.SetCount((int)rownum);
            if (paing.PageNum > 1)
            {
                sortin = SqlDBbatBuilder <T> .InitiSorting(this.Mapper, sortin);

                var kMapper      = (IEntityMapper <K>)EntityMapperCacheManager.GetMapperCacheManager()[typeof(K).Name].Value;
                var fok          = (from t in this.Mapper.Relevances where t.Type == typeof(K) select t).SingleOrDefault();
                var relevanceStr = string.Empty;
                var p            = SqlDBbatBuilder <T> .FilterProperty <K>(this.Mapper, kMapper, fok, Type, out relevanceStr);

                var str = new StringBuilder($"select * from  ");
                str.Append($"(select  top({paing.PageNumber * paing.Showline}) {string.Join(",", p)}, row_number() over(order by {string.Join(",", sortin)} ) as row  from {relevanceStr}    ");
                str.Append($"{(wheres == null ? string.Empty : wheres.ToString())}) as paging ");
                str.Append($"where row>{paing.Showline * (paing.PageNumber - 1)}");
                var bar = new SqlDBbatBuilder <T>(this.Mapper);
                bar.Additional(str.ToString(), wheres);
                this.Execute <K>(entitys, bar, s);
            }
            else
            {
                this.Select <K>(entitys, paing.Showline, wheres, Type, disabled);
            }
            return(paing.Count);
        }