public override void UpdateBatBuilder(IWhereGroup where, IList <IProperty> disabled = null) { var propertys = MySqlDBbatBuilder <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())}"); }
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(Convert.ToInt32(rownum)); if (paing.PageNum > 1) { sortin = MySqlDBbatBuilder <T> .InitiSorting(this.Mapper, sortin); var p = MySqlDBbatBuilder <T> .FilterProperty(this.Mapper, disabled); var str = new StringBuilder($"select {string.Join(",", p)} from {this.Mapper.TableName } {(wheres == null ? string.Empty : wheres.ToString())} order by {string.Join(",", sortin)} limit {paing.Showline * (paing.PageNumber - 1)}, { paing.Showline}"); var bar = new MySqlDBbatBuilder <T>(this.Mapper); bar.Additional(str.ToString(), wheres); this.Execute(entitys, bar, s); } else { this.Select(entitys, wheres, disabled, sortin); } return(paing.Count); }
public override void InsertBatBuilder(IList <IProperty> disabled = null) { this._propertys = MySqlDBbatBuilder <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))})"); }
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 = MySqlDBbatBuilder <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)} "); }
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.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) { sortin = MySqlDBbatBuilder <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 = MySqlDBbatBuilder <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 MySqlDBbatBuilder <T>(this.Mapper); bar.Additional(str.ToString(), wheres); this.Execute <K>(entitys, bar, s); } else { this.Select(entitys, wheres, disabled, sortin); } return(paing.Count); }