public EntityDynAttribute[] GetCustomAttributes(Type attributeType, bool inherit)
        {
            if (inherit == false)
            {
                List <EntityDynAttribute> attrs = new List <EntityDynAttribute>();
                foreach (EntityDynAttribute attr in _attributes)
                {
                    if (attributeType.IsAssignableFrom(attr.GetType()))
                    {
                        attrs.Add(attr);
                    }
                }

                if (attrs.Count > 0)
                {
                    return(attrs.ToArray());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                List <EntityDynAttribute> attrs = new List <EntityDynAttribute>();
                foreach (EntityDynAttribute attr in _attributes)
                {
                    if (attributeType.IsAssignableFrom(attr.GetType()))
                    {
                        attrs.Add(attr);
                    }
                }

                DynEntityType parentType = DynEntityTypeManager.GetEntityType(this.EntityType.BaseEntityName);
                while (parentType != null)
                {
                    if (parentType.ContainsProperty(_name))
                    {
                        foreach (EntityDynAttribute attr in parentType.GetProperty(_name).Attributes)
                        {
                            if (attributeType.IsAssignableFrom(attr.GetType()))
                            {
                                attrs.Add(attr);
                            }
                        }
                    }

                    parentType = DynEntityTypeManager.GetEntityType(parentType.BaseEntityName);
                }

                if (attrs.Count > 0)
                {
                    return(attrs.ToArray());
                }
                else
                {
                    return(null);
                }
            }
        }
示例#2
0
        private static string GetOutputNamespace(string typeName)
        {
            string outNs = "Entities";

            DynEntityType entityType = DynEntityTypeManager.GetEntityType(typeName);

            //OutputNamespaceDynAttribute outNsAttr = DynCodeGenHelper.GetEntityAttribute<OutputNamespaceDynAttribute>(typeName);
            //if (outNsAttr != null)
            //{
            //    return outNsAttr.Namespace;
            //}
            //else
            //{
            //    return outNs;
            //}

            if (entityType != null)
            {
                return(entityType.Namespace);
            }
            else
            {
                return(outNs);
            }
        }
示例#3
0
        /// <summary>
        /// Flush all EntityConfigurations in MetaDataManager into EntityTypeManager
        /// </summary>
        public static void EntityConfiguration2EntityTypes()
        {
            foreach (EntityConfiguration ec in MetaDataManager.Entities)
            {
                string nameSpace, typeName;
                Util.SplitFullName(ec.Name, out nameSpace, out typeName);

                if (DynEntityTypeManager.GetEntityType(typeName) == null)
                {
                    DynEntityTypeManager.Entities.Add(EntityConfiguration2EntityType(ec));
                }
            }
        }
示例#4
0
        /// <summary>
        /// 基于实体类型构造对象
        /// </summary>
        /// <param name="entityType"></param>
        public DynEntity(string typeName)
        {
            // 这里应该是从数据库中加载
            DynEntityType entityType = DynEntityTypeManager.GetEntityType(typeName);

            if (entityType == null)
            {
                throw new ApplicationException("实体类型不能为空");
            }

            this.PropertyChanged += new PropertyChangedHandler(Entity_PropertyChanged);
            isAttached            = false;

            _entityType = entityType;

            int normalCnt = 0;
            int queryCnt  = 0;

            foreach (DynPropertyConfiguration entityProperty in _entityType.GetProperties())
            {
                if (entityProperty.IsQueryProperty == true)
                {
                    if (entityProperty.IsArray)
                    {
                        _queryPropertyNameIdMap.Add("_" + entityProperty.Name, queryCnt++);
                        _queryPropertyValues.Add(null);
                    }
                    else
                    {
                        QueryDynAttribute qa        = entityProperty.GetPropertyQueryAttribute();
                        DynQueryDescriber describer = new DynQueryDescriber(qa, entityProperty, entityProperty.PropertyOriginalEntityType, _entityType.Name);

                        _normalPropertyNameIdMap.Add("_" + entityProperty.Name + "_" + describer.RelatedForeignKey, normalCnt++);
                        _fkPropertyNameNormalPropertyNameMap.Add("_" + entityProperty.Name + "_" + describer.RelatedForeignKey, entityProperty.Name);
                        _normalPropertyValues.Add(null);

                        _queryPropertyNameIdMap.Add("_" + entityProperty.Name, queryCnt++);
                        _queryPropertyValues.Add(null);
                    }
                }
                else
                {
                    _normalPropertyNameIdMap.Add("_" + entityProperty.Name, normalCnt++);
                    _normalPropertyValues.Add(null);
                }
            }
        }
        public EntityDynAttribute[] GetCustomAttributes(bool inherit)
        {
            if (inherit == false)
            {
                if (_attributes.Count > 0)
                {
                    return(_attributes.ToArray());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                List <EntityDynAttribute> attrs = new List <EntityDynAttribute>();
                attrs.AddRange(_attributes);

                DynEntityType parentType = DynEntityTypeManager.GetEntityType(this.EntityType.BaseEntityName);
                while (parentType != null)
                {
                    attrs.AddRange(parentType.GetProperty(_name).Attributes);

                    parentType = DynEntityTypeManager.GetEntityType(parentType.BaseEntityName);
                }

                if (attrs.Count > 0)
                {
                    return(attrs.ToArray());
                }
                else
                {
                    return(null);
                }
            }
        }