Exemplo n.º 1
0
 public MpperRelevanceItem(DataEntity entity, IProperty property, int index)
 {
     this.entity     = entity;
     this.property   = property;
     this.index      = index;
     this.setHandler = EntityMapperCacheManager.GetMapperCacheManager()[entity.GetType().Name].Value.FindSetDynamicHandle(property.Name);
 }
Exemplo n.º 2
0
 public DBHelperBase()
 {
     this._conn   = this.GetIDbConntion();
     this._mapper = EntityMapperCacheManager.GetMapperCacheManager()[typeof(T).Name].Value;
     this._bat    = this.GetDBbatBuilder();
     this._entity = new T();
 }
Exemplo n.º 3
0
        public RelevanceMap(string aliaName, IProperty foreignKey, IProperty entity, string primaryKeyName = null)
        {
            this.AliaName       = aliaName;
            this.ForeignKey     = foreignKey;
            this.Type           = entity.Type;
            this.EntityProperty = entity;
            var a = EntityMapperCacheManager.GetMapperCacheManager()[entity.Type.Name];

            this.PrimaryKey = string.IsNullOrWhiteSpace(primaryKeyName) ? a.Value.PrimaryKey : a.Value.GetPropertField(primaryKeyName);
        }
Exemplo n.º 4
0
        public override void SelectBatBuilder <K>(IWhereGroup where, int num, JoinType Type, IEnumerable <IProperty> disabled, IList <ISorting> sortin)
        {
            sortin = InitiSorting(this._mapper, sortin);
            var kMapper      = (IEntityMapper <K>)EntityMapperCacheManager.GetMapperCacheManager()[typeof(K).Name].Value;
            var fok          = (from t in _mapper.Relevances where t.Type == typeof(K) select t).SingleOrDefault();
            var relevanceStr = string.Empty;

            this._propertys = FilterProperty <K>(this._mapper, kMapper, fok, Type, out relevanceStr);
            this._sqltext   = new StringBuilder();
            this._sqltext.Append($"select  {(num > 0 ? $" top({num})" : string.Empty) }   {string.Join(",", this._propertys)} ");
            this._sqltext.Append($"from {relevanceStr}  {(where == null ? string.Empty : where.ToString())}");
            this._sqltext.Append(sortin == null ? string.Empty : $" order by {string.Join(",", sortin)} ");
        }
Exemplo n.º 5
0
        public override void ScalarBatBuilder <K>(IWhereGroup where, int num, JoinType Type, IEnumerable <Polymerize> polymerizes, IEnumerable <IProperty> disabled, IList <ISorting> sortin)
        {
            sortin = InitiSorting(this._mapper, sortin);
            var kMapper      = (IEntityMapper <K>)EntityMapperCacheManager.GetMapperCacheManager()[typeof(K).Name].Value;
            var fok          = (from t in _mapper.Relevances where t.Type == typeof(K) select t).SingleOrDefault();
            var relevanceStr = string.Empty;

            this._propertys = FilterProperty <K>(this._mapper, kMapper, fok, Type, out relevanceStr, disabled, polymerizes);
            var filed_str      = string.Join(",", this._propertys);
            var polymerizeText = polymerizes == null ? string.Empty : $"{string.Join(",", polymerizes)} {(string.IsNullOrWhiteSpace(filed_str)?string.Empty:",")}";

            this._sqltext = new StringBuilder();
            this._sqltext.Append($"select {string.Join(",", polymerizes)}  ");
            this._sqltext.Append($"from {relevanceStr}  {(where == null ? string.Empty : where.ToString())}");
            this.where = where;
        }
Exemplo n.º 6
0
        private static MpperRelevanceItem GetForeignDataEntity <T>(string columnName, int index, IEntityMapper <T> mapper, Dictionary <string, DataEntity> cache, params string[] typename)
        {
            int       indexStr  = columnName.IndexOf("_");
            var       a         = columnName.Substring(0, indexStr);
            var       fieldName = columnName.Substring(indexStr += 1, columnName.Length - indexStr);
            IProperty p;

            foreach (var t in typename)
            {
                p = EntityMapperCacheManager.GetMapperCacheManager()[t].Value.GetPropertField(fieldName) as IProperty;
                if (p != null)
                {
                    return(new MpperRelevanceItem(cache[a], p, index));
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        public override void SelectBatBuilder <K1, K2>(IWhereGroup where, int num, JoinType Type, IEnumerable <IProperty> disabled, IList <ISorting> sortin)
        {
            sortin = InitiSorting(this._mapper, sortin);
            var mp           = EntityMapperCacheManager.GetMapperCacheManager();
            var k1Mapper     = (IEntityMapper <K1>)mp[typeof(K1).Name].Value;
            var k2Mapper     = (IEntityMapper <K2>)mp[typeof(K2).Name].Value;
            var FK           = (from t in _mapper.Relevances where t.Type == typeof(K1) || t.Type == typeof(K2) select t).ToArray();
            var relevanceStr = string.Empty;

            this._propertys = FilterProperty <K1, K2>(this._mapper, k1Mapper, k2Mapper, FK, Type, out relevanceStr, disabled);
            var filed_str = string.Join(",", this._propertys);

            this._sqltext = new StringBuilder();
            this._sqltext.Append($"select  {(num > 0 ? $" top({num})" : string.Empty) }   {string.Join(",", this._propertys)} ");
            this._sqltext.Append($"from {relevanceStr}  {(where == null ? string.Empty : where.ToString())}");
            this._sqltext.Append(sortin == null ? string.Empty : $" order by {string.Join(",", sortin)} ");
            this.where = where;
        }
Exemplo n.º 8
0
        public static T Parse <T>(IEnumerable <JsonObject> items) where T : IEntity, new()
        {
            var e = new T();

            var c = EntityMapperCacheManager.GetMapperCacheManager()[e.GetType().Name].Value;

            foreach (var a in e.GetFieldItems())
            {
                foreach (var b in items)
                {
                    if (string.Compare(a.Name, b.Key) == 0)
                    {
                        var s = Convert.ChangeType(b.Value, a.Type);
                        c.FindSetDynamicHandle(a.Name)(e, s, a.Type.IsEnum ? typeof(int) : a.Type);
                    }
                }
            }
            return(e);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public IEnumerable <IField> GetFieldItems()
 {
     return(EntityMapperCacheManager.GetMapperCacheManager()[this.GetType().Name].Value.Propertys);
 }
Exemplo n.º 11
0
 public IField GetFilter(string fieldName)
 {
     return(EntityMapperCacheManager.GetMapperCacheManager()[this.GetType().Name].Value.GetPropertField(fieldName));
 }