Esempio n. 1
0
        /// <summary>
        /// Gets the modified properties of this entity, not including query properties and properties of base entity's.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The modified properties</returns>
        public Dictionary <string, object> GetModifiedProperties(DynEntityType entityType)
        {
            EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(entityType.FullName);

            if (string.IsNullOrEmpty(entityType.BaseEntityName))
            {
                return(changedProperties);
            }

            List <string> toRemoveItems = new List <string>();

            foreach (string item in changedProperties.Keys)
            {
                PropertyConfiguration pc = ec.GetPropertyConfiguration(item);
                if (pc == null || pc.IsInherited || pc.IsPrimaryKey)
                {
                    toRemoveItems.Add(item);
                }
            }
            Dictionary <string, object> retProperties = new Dictionary <string, object>();

            foreach (string item in changedProperties.Keys)
            {
                if (!toRemoveItems.Contains(item))
                {
                    retProperties.Add(item, changedProperties[item]);
                }
            }
            return(retProperties);
        }
Esempio n. 2
0
        private static void GuessPrimaryKey(EntityConfiguration ec, List <string> primaryKeys)
        {
            //check name = ID or GUID column first
            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if (pc.MappingName.ToUpper() == "ID" || pc.MappingName.ToUpper() == "GUID")
                {
                    primaryKeys.Add(pc.MappingName);
                    return;
                }
            }

            //check the first ends with ID or Guid column
            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if (pc.MappingName.ToUpper().EndsWith("ID") || pc.MappingName.ToUpper().EndsWith("GUID"))
                {
                    primaryKeys.Add(pc.MappingName);
                    return;
                }
            }

            //or threat the first column as DEFAULT_KEY column
            primaryKeys.Add(ec.Properties[0].MappingName);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the modified properties of this entity, not including query properties and properties of base entity's.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The modified properties</returns>
        public Dictionary <string, object> GetModifiedProperties(Type type)
        {
            EntityConfiguration ec = MetaDataManager.GetEntityConfiguration(type.ToString());

            if (ec.BaseEntity == null && type == this.GetType())
            {
                return(changedProperties);
            }

            Check.Require(typeof(Entity).IsAssignableFrom(type), "type must be an Entity");

            List <string> toRemoveItems = new List <string>();

            foreach (string item in changedProperties.Keys)
            {
                PropertyConfiguration pc = ec.GetPropertyConfiguration(item);
                if (pc == null || pc.IsInherited || pc.IsPrimaryKey)
                {
                    toRemoveItems.Add(item);
                }
            }
            Dictionary <string, object> retProperties = new Dictionary <string, object>();

            foreach (string item in changedProperties.Keys)
            {
                if (!toRemoveItems.Contains(item))
                {
                    retProperties.Add(item, changedProperties[item]);
                }
            }
            return(retProperties);
        }
        /// <summary>
        /// Gets the entity configuration.
        /// </summary>
        /// <param name="typeFullName">Name of the type.</param>
        /// <returns>The entity configuration</returns>
        public static EntityConfiguration GetEntityConfiguration(string typeFullName)
        {
            if (_entities != null)
            {
                foreach (EntityConfiguration item in _entities)
                {
                    if (item.Name == typeFullName)
                    {
                        return(item);
                    }
                }
            }

            Type type = Util.GetType(typeFullName);
            EntityConfiguration embeddedEc = GetEmbeddedEntityConfigurationsFromEntityType(type);

            if (embeddedEc != null)
            {
                LoadEmbeddedEntityConfigurationsFromLoadedEntities();
                ParseNonRelatedEntities();
            }

            //check again
            foreach (EntityConfiguration item in _entities)
            {
                if (item.Name == typeFullName)
                {
                    return(item);
                }
            }

            throw new CouldNotFoundEntityConfigurationOfEntityException(typeFullName);
        }
Esempio n. 5
0
        /// <summary>
        /// Called when query one property changed.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        protected void OnQueryOnePropertyChanged(string propertyName, object oldValue, object newValue)
        {
            bool isLoadedBefore = IsQueryPropertyLoaded(propertyName);

            SetPropertyLoaded(propertyName);

            if (!isLoadedBefore)
            {
                return;
            }

            if (oldValue == newValue)
            {
                return;
            }

            EntityConfiguration   ec = MetaDataManager.GetEntityConfiguration(EntityType.FullName);
            PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName);

            if ((!(pc.IsContained || pc.QueryType == "ManyToManyQuery")))
            {
                return;
            }

            if (oldValue != null)
            {
                OnQueryPropertyItemRemove(propertyName, oldValue);
            }

            if (newValue != null)
            {
                OnQueryPropertyItemAdd(propertyName, newValue);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Queries array of the specified return entity type.
        /// </summary>
        /// <param name="returnEntityType">Type of the return entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="baseEntity">The base entity.²»ÊÇ»ùÀà</param>
        /// <returns>The query result.</returns>
        protected object Query(Type returnEntityType, string propertyName, Entity baseEntity)
        {
            if (onQuery != null)
            {
                EntityConfiguration   ec = baseEntity.GetEntityConfiguration();
                PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName);

                return(onQuery(returnEntityType, propertyName, pc.QueryWhere, pc.QueryOrderBy, baseEntity));
            }

            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Called when removed item from query property.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="item">The item.</param>
        protected void OnQueryPropertyItemRemove(string propertyName, object item)
        {
            Check.Require(item != null, "item to remove could not be null.");

            bool isLoadedBefore = IsQueryPropertyLoaded(propertyName);

            SetPropertyLoaded(propertyName);

            if (!isLoadedBefore)
            {
                return;
            }

            EntityConfiguration   ec = MetaDataManager.GetEntityConfiguration(EntityType.FullName);
            PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName);

            if ((!(pc.IsContained || pc.QueryType == "ManyToManyQuery")))
            {
                return;
            }

            bool isInSaveList = false;

            lock (toSaveRelatedPropertyObjects)
            {
                List <object> values = null;
                if (toSaveRelatedPropertyObjects.TryGetValue(propertyName, out values) && toSaveRelatedPropertyObjects[propertyName].Contains(item))
                {
                    values.Remove(item);
                    isInSaveList = true;
                }
            }

            if (!isInSaveList)
            {
                lock (toDeleteRelatedPropertyObjects)
                {
                    List <object> values = null;
                    if (!toDeleteRelatedPropertyObjects.TryGetValue(propertyName, out values))
                    {
                        values = new List <object>();
                        toDeleteRelatedPropertyObjects.Add(propertyName, values);
                    }

                    if (!values.Contains(item))
                    {
                        values.Add(item);
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the create property mapping column pks.
        /// </summary>
        /// <param name="ec">The ec.</param>
        /// <returns>Column pks</returns>
        public static string[] GetCreatePropertyMappingColumnNames(EntityConfiguration ec)
        {
            List <string> insertColumnNames = new List <string>();

            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if ((!(pc.IsReadOnly && ec.BaseEntity == null)) && ((!pc.IsQueryProperty) || (pc.QueryType == "FkReverseQuery")) && ((!pc.IsInherited) || pc.IsPrimaryKey))
                {
                    insertColumnNames.Add(pc.MappingName);
                }
            }

            return(insertColumnNames.ToArray());
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the property mapping column names.
        /// </summary>
        /// <param name="ec">The ec.</param>
        /// <returns>Column names</returns>
        public static string[] GetPropertyMappingColumnNames(EntityConfiguration ec)
        {
            List <string> columnNames = new List <string>();

            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if ((!pc.IsQueryProperty) || (pc.QueryType == "FkReverseQuery"))
                {
                    columnNames.Add(pc.MappingName);
                }
            }

            return(columnNames.ToArray());
        }
Esempio n. 10
0
        /// <summary>
        /// Gets the create property mapping column types.
        /// </summary>
        /// <param name="ec">The ec.</param>
        /// <returns></returns>
        public static DbType[] GetCreatePropertyMappingColumnTypes(EntityConfiguration ec)
        {
            List <DbType> insertColumnTypes = new List <DbType>();

            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if ((!(pc.IsReadOnly && ec.BaseEntity == null)) && (!pc.IsQueryProperty) && ((!pc.IsInherited) || pc.IsPrimaryKey))
                {
                    insertColumnTypes.Add(pc.DbType);
                }
            }

            return(insertColumnTypes.ToArray());
        }
Esempio n. 11
0
        /// <summary>
        /// Queries array of the specified return entity type.
        /// </summary>
        /// <param name="returnEntityType">Type of the return entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="baseEntity">The base entity.</param>
        /// <returns>The query result.</returns>
        protected DynEntity[] Query(DynEntity returnEntityType, string propertyName, DynEntity baseEntity)
        {
            if (onQuery != null)
            {
                EntityConfiguration   ec = MetaDataManager.GetEntityConfiguration(baseEntity.EntityType.FullName);
                PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName);

                try
                {
                    return(onQuery(returnEntityType, propertyName, pc.QueryWhere, pc.QueryOrderBy, baseEntity));
                }
                catch (Exception ex)
                {
                    onQuery = null;
                    throw ex;
                }
            }
            return(null);
        }
Esempio n. 12
0
        /// <summary>
        /// Gets the primary key mapping column names.
        /// </summary>
        /// <param name="ec">The ec.</param>
        /// <returns></returns>
        public static string[] GetPrimaryKeyMappingColumnNames(EntityConfiguration ec)
        {
            List <string> primaryKeys = new List <string>();

            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if (pc.IsPrimaryKey)
                {
                    primaryKeys.Add(pc.MappingName);
                }
            }

            if (primaryKeys.Count == 0)
            {
                //take the most possible column as a single primary DEFAULT_KEY
                GuessPrimaryKey(ec, primaryKeys);
            }

            return(primaryKeys.ToArray());
        }
        public static bool EntitiesIsChange(EntityConfiguration ec)
        {
            bool ok = false;
            EntityConfiguration oec = new EntityConfiguration();

            foreach (EntityConfiguration item in _entities)
            {
                if (item.Name == ec.Name)
                {
                    oec = item;
                    ok  = item.Properties.Length == ec.Properties.Length;
                    break;
                }
            }
            if (!ok)
            {
                _entities.Remove(oec);
                _entities.Add(ec);
            }
            return(ok);
        }
        private static EntityConfiguration GetEmbeddedEntityConfigurationsFromEntityType(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            object[] attrs = type.GetCustomAttributes(typeof(EmbeddedEntityConfigurationAttribute), false);

            if (attrs != null && attrs.Length > 0)
            {
                EmbeddedEntityConfigurationAttribute   embeddedConfigAttr = (EmbeddedEntityConfigurationAttribute)attrs[0];
                System.Xml.Serialization.XmlSerializer serializer         = new System.Xml.Serialization.XmlSerializer(typeof(EntityConfiguration));
                StringReader        sr         = new StringReader(embeddedConfigAttr.Content);
                EntityConfiguration embeddedEc = (EntityConfiguration)serializer.Deserialize(sr);
                sr.Close();
                return(embeddedEc);
            }

            return(null);
        }
Esempio n. 15
0
        /// <summary>
        /// Called when query property changed.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="oldValues">The old values.</param>
        /// <param name="newValues">The new values.</param>
        protected void OnQueryPropertyChanged(string propertyName, object oldValues, object newValues)
        {
            bool isLoadedBefore = IsQueryPropertyLoaded(propertyName);

            SetPropertyLoaded(propertyName);

            if (newValues != null)
            {
                BindArrayListEventHandlers(propertyName, newValues);
            }

            if (!isLoadedBefore)
            {
                return;
            }

            EntityConfiguration   ec = MetaDataManager.GetEntityConfiguration(EntityType.FullName);
            PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName);

            if ((!(pc.IsContained || pc.QueryType == "ManyToManyQuery")) || oldValues == newValues)
            {
                return;
            }

            if (oldValues != null)
            {
                foreach (object oldValue in (IEnumerable)oldValues)
                {
                    OnQueryPropertyItemRemove(propertyName, oldValue);
                }
            }

            if (newValues != null)
            {
                foreach (object newValue in (IEnumerable)newValues)
                {
                    OnQueryPropertyItemAdd(propertyName, newValue);
                }
            }
        }
        private static void LoadEmbeddedEntityConfigurationsFromLoadedEntities()
        {
            List <EntityConfiguration> list = new List <EntityConfiguration>();

            try
            {
                System.Reflection.Assembly[] asses = AppDomain.CurrentDomain.GetAssemblies();

                for (int i = asses.Length - 1; i >= 0; i--)
                {
                    System.Reflection.Assembly ass = asses[i];
                    try
                    {
                        foreach (Type t in ass.GetTypes())
                        {
                            if (t.IsSubclassOf(typeof(Entity)) && t != typeof(Entity) && (!t.IsAbstract))
                            {
                                EntityConfiguration item = GetEmbeddedEntityConfigurationsFromEntityType(t);
                                if (item != null)
                                {
                                    list.Add(item);
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }

            if (list.Count > 0)
            {
                MetaDataManager.AddEntityConfigurations(list.ToArray());
            }
        }
Esempio n. 17
0
        /// <summary>
        /// new an EntityConfiguration from an EntityType
        /// </summary>
        /// <param name="entityType"></param>
        /// <returns></returns>
        public static EntityConfiguration EntityType2EntityConfiguration(DynEntityType entityType)
        {
            EntityConfiguration ec = new EntityConfiguration();

            ec.Name = entityType.FullName;

            EntityDynAttribute attr = entityType.GetCustomAttribute(typeof(MappingNameDynAttribute));

            if (attr != null)
            {
                ec.MappingName = (attr as MappingNameDynAttribute).Name;
            }
            else
            {
                ec.MappingName = entityType.Name;
            }

            entityType.MappingName = ec.MappingName;


            attr = entityType.GetCustomAttribute(typeof(CommentDynAttribute));
            if (attr != null)
            {
                ec.Comment = (attr as CommentDynAttribute).Content;
            }
            else
            {
                ec.Comment = "";
            }

            entityType.Comment = ec.Comment;

            attr = entityType.GetCustomAttribute(typeof(BatchUpdateDynAttribute));
            if (attr != null)
            {
                ec.BatchSize = (attr as BatchUpdateDynAttribute).BatchSize;
            }
            else
            {
                ec.BatchSize = 0;
            }

            entityType.BatchSize = ec.BatchSize;

            if (string.IsNullOrEmpty(entityType.BaseEntityName))
            {
                ec.BaseEntity = null;
            }

            else
            {
                ec.BaseEntity = entityType.Namespace + "." + entityType.BaseEntityName;
            }

            attr = entityType.GetCustomAttribute(typeof(CustomDataDynAttribute));
            if (attr != null)
            {
                ec.CustomData = (attr as CustomDataDynAttribute).Data;
            }
            else
            {
                ec.CustomData = "";
            }

            entityType.CustomData = ec.CustomData;

            attr = entityType.GetCustomAttribute(typeof(AdditionalSqlScriptDynAttribute));
            if (attr != null)
            {
                ec.AdditionalSqlScript = (attr as AdditionalSqlScriptDynAttribute).Sql;
            }
            else
            {
                ec.AdditionalSqlScript = "";
            }

            entityType.AdditionalSqlScript = ec.AdditionalSqlScript;

            attr = entityType.GetCustomAttribute(typeof(ReadOnlyDynAttribute));
            if (attr != null)
            {
                ec.IsReadOnly = true;
            }
            else
            {
                ec.IsReadOnly = false;
            }
            entityType.IsReadOnly = ec.IsReadOnly;

            attr = entityType.GetCustomAttribute(typeof(AutoPreLoadDynAttribute));
            if (attr != null)
            {
                ec.IsAutoPreLoad = true;
            }
            else
            {
                ec.IsAutoPreLoad = false;
            }
            entityType.IsAutoPreLoad = ec.IsAutoPreLoad;

            attr = entityType.GetCustomAttribute(typeof(RelationDynAttribute));
            if (attr != null)
            {
                ec.IsRelation = true;
            }
            else
            {
                ec.IsRelation = false;
            }
            entityType.IsRelation = ec.IsRelation;

            //根据DynPropertyConfigurationCollection构造PropertyConfiguration
            List <PropertyConfiguration> pcList = new List <PropertyConfiguration>();
            //TODO:此处如果支持继承关系需要调整
            DynPropertyConfigurationCollection allProperties = entityType.GetProperties();

            foreach (DynPropertyConfiguration property in allProperties)
            {
                PropertyConfiguration pc = new PropertyConfiguration();

                pc.IsInherited = property.IsInherited;
                pc.InheritEntityMappingName = property.InheritEntityMappingName;

                attr            = property.GetPropertyAttribute(typeof(PrimaryKeyDynAttribute));
                pc.IsPrimaryKey = (attr != null);

                IndexPropertyDynAttribute ipa = property.GetPropertyAttribute(typeof(IndexPropertyDynAttribute)) as IndexPropertyDynAttribute;
                if (ipa != null)
                {
                    pc.IsIndexProperty           = true;
                    pc.IsIndexPropertyDesc       = ipa.IsDesc;
                    property.IsIndexProperty     = true;
                    property.IsIndexPropertyDesc = ipa.IsDesc;
                }

                attr         = property.GetPropertyAttribute(typeof(NotNullDynAttribute));
                pc.IsNotNull = (attr != null);

                attr = property.GetPropertyAttribute(typeof(SerializationIgnoreDynAttribute));
                pc.IsSerializationIgnore = (attr != null);

                RelationKeyDynAttribute rka = property.GetPropertyAttribute(typeof(RelationKeyDynAttribute)) as RelationKeyDynAttribute;
                if (rka != null)
                {
                    pc.IsRelationKey           = true;
                    pc.RelatedType             = GetOutputNamespace(rka.RelatedType) + "." + rka.RelatedType;
                    pc.RelatedForeignKey       = rka.RelatedPk;
                    property.IsRelationKey     = true;
                    property.RelatedType       = pc.RelatedType;
                    property.RelatedForeignKey = rka.RelatedPk;
                }

                FriendKeyDynAttribute fka = property.GetPropertyAttribute(typeof(FriendKeyDynAttribute)) as FriendKeyDynAttribute;
                if (fka != null)
                {
                    pc.IsFriendKey             = true;
                    pc.RelatedForeignKey       = fka.RelatedEntityPk;
                    pc.RelatedType             = GetOutputNamespace(fka.RelatedEntityType) + "." + fka.RelatedEntityType;
                    property.IsFriendKey       = true;
                    property.RelatedForeignKey = fka.RelatedEntityPk;
                    property.RelatedType       = pc.RelatedType;
                }

                MappingNameDynAttribute mna = property.GetPropertyAttribute(typeof(MappingNameDynAttribute)) as MappingNameDynAttribute;
                if (mna != null)
                {
                    pc.MappingName       = mna.Name;
                    property.MappingName = mna.Name;
                }

                CommentDynAttribute ca = property.GetPropertyAttribute(typeof(CommentDynAttribute)) as CommentDynAttribute;
                if (ca != null)
                {
                    pc.Comment       = ca.Content;
                    property.Comment = ca.Content;
                }

                attr = property.GetPropertyAttribute(typeof(CustomDataDynAttribute));
                if (attr != null)
                {
                    pc.CustomData = ((CustomDataDynAttribute)attr).Data;
                }

                pc.IsReadOnly = property.IsReadOnly;
                pc.Name       = property.Name;


                SqlTypeDynAttribute sta = property.GetPropertyAttribute(typeof(SqlTypeDynAttribute)) as SqlTypeDynAttribute;
                if (sta != null && (!string.IsNullOrEmpty(sta.Type)))
                {
                    pc.SqlType               = sta.Type;
                    pc.SqlDefaultValue       = sta.DefaultValue;
                    property.SqlType         = sta.Type;
                    property.SqlDefaultValue = sta.DefaultValue;
                }

                QueryDynAttribute qa = property.GetPropertyQueryAttribute();
                if (qa != null)
                {
                    pc.IsQueryProperty = true;
                    pc.QueryType       = qa.QueryType.ToString();

                    property.PropertyOriginalEntityType = property.PropertyType;
                    property.IsQueryProperty            = true;


                    string propertyEntityType = property.PropertyType;
                    //if (property.IsArray)
                    //{
                    //    propertyEntityType = property.PropertyType;
                    //}
                    DynQueryDescriber describer = new DynQueryDescriber(qa, property, propertyEntityType, entityType.Name);

                    pc.IsLazyLoad         = describer.LazyLoad;
                    pc.QueryOrderBy       = describer.OrderBy;
                    pc.QueryWhere         = describer.Where;
                    property.IsLazyLoad   = describer.LazyLoad;
                    property.QueryOrderBy = describer.OrderBy;
                    property.QueryWhere   = describer.Where;

                    if (describer.RelationType != null)
                    {
                        pc.RelationType = GetOutputNamespace(describer.RelationType) + "." + describer.RelationType;
                    }
                    pc.IsContained             = describer.Contained;
                    pc.RelatedForeignKey       = describer.RelatedForeignKey;
                    property.IsContained       = describer.Contained;
                    property.RelatedForeignKey = describer.RelatedForeignKey;
                    if (describer.RelatedType != null)
                    {
                        pc.RelatedType       = GetOutputNamespace(describer.RelatedType) + "." + describer.RelatedType;
                        property.RelatedType = pc.RelatedType;
                    }

                    if (property.IsArray)
                    {
                        pc.PropertyType = GetOutputNamespace(property.PropertyType) + "." + property.PropertyType + "ArrayList";
                    }
                    else
                    {
                        pc.PropertyType = GetOutputNamespace(property.PropertyType) + "." + property.PropertyType;
                    }
                    property.PropertyType = pc.PropertyType;

                    if (qa.QueryType == QueryType.FkReverseQuery)
                    {
                        if (string.IsNullOrEmpty(describer.RelatedForeignKeyType) != true)
                        {
                            pc.PropertyMappingColumnType = describer.RelatedForeignKeyType ?? typeof(string).ToString();
                        }
                        else
                        {
                            pc.PropertyMappingColumnType = string.IsNullOrEmpty(describer.RelatedForeignKeyType) ? "" : typeof(string).ToString();
                        }
                        property.PropertyMappingColumnType = pc.PropertyMappingColumnType;
                    }

                    if (qa.QueryType == QueryType.FkQuery)
                    {
                        pc.RelatedForeignKey = describer.RelatedForeignKey;
                        pc.RelatedType       = GetOutputNamespace(describer.RelatedType) + "." + describer.RelatedType;

                        property.RelatedForeignKey = describer.RelatedForeignKey;
                        property.RelatedType       = pc.RelatedType;
                    }
                }
                else
                {
                    pc.PropertyType = property.PropertyType;
                }

                pcList.Add(pc);
            }
            ec.Properties = pcList.ToArray();

            return(ec);
        }
Esempio n. 18
0
        /// <summary>
        /// new an EntityType from an EntityConfiguration
        /// </summary>
        /// <param name="ec"></param>
        /// <returns></returns>
        public static DynEntityType EntityConfiguration2EntityType(EntityConfiguration ec)
        {
            string nameSpace, typeName, baseName;

            Util.SplitFullName(ec.Name, out nameSpace, out typeName);

            DynEntityType et;

            if (string.IsNullOrEmpty(ec.BaseEntity))
            {
                et = new DynEntityType(typeName);
            }
            else
            {
                Util.SplitFullName(ec.BaseEntity, out nameSpace, out baseName);
                et = new DynEntityType(typeName, baseName);
            }
            et.AdditionalSqlScript = ec.AdditionalSqlScript;
            et.BaseEntityName      = ec.BaseEntity;
            et.BatchSize           = ec.BatchSize;
            et.Comment             = ec.Comment;
            et.CustomData          = ec.CustomData;
            et.IsAutoPreLoad       = ec.IsAutoPreLoad;
            et.IsBatchUpdate       = ec.IsBatchUpdate;
            et.IsReadOnly          = ec.IsReadOnly;
            et.IsRelation          = ec.IsRelation;
            et.MappingName         = ec.MappingName;
            et.Namespace           = nameSpace;
            et.Name     = typeName;
            et.ViewName = ec.ViewName;


            if (string.IsNullOrEmpty(nameSpace) == false)
            {
                et.Attributes.Add(new OutputNamespaceDynAttribute(nameSpace));
            }

            if (string.IsNullOrEmpty(ec.MappingName) == false | string.IsNullOrEmpty(ec.ViewName) == false)
            {
                et.Attributes.Add(new MappingNameDynAttribute(ec.MappingName));
            }

            if (string.IsNullOrEmpty(ec.Comment) == false)
            {
                et.Attributes.Add(new CommentDynAttribute(ec.Comment));
            }

            if (string.IsNullOrEmpty(ec.CustomData) == false)
            {
                et.Attributes.Add(new CustomDataDynAttribute(ec.CustomData));
            }

            if (string.IsNullOrEmpty(ec.AdditionalSqlScript) == false)
            {
                et.Attributes.Add(new AdditionalSqlScriptDynAttribute(ec.AdditionalSqlScript));
            }

            if (ec.IsReadOnly)
            {
                et.Attributes.Add(new ReadOnlyDynAttribute());
            }

            if (ec.IsAutoPreLoad)
            {
                et.Attributes.Add(new AutoPreLoadDynAttribute());
            }

            if (ec.IsBatchUpdate)
            {
                et.Attributes.Add(new BatchUpdateDynAttribute(ec.BatchSize));
            }

            if (ec.IsRelation)
            {
                et.Attributes.Add(new RelationDynAttribute());
            }

            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if (pc.IsInherited)
                {
                    continue;
                }

                DynPropertyConfiguration property = new DynPropertyConfiguration(pc.Name);
                property.PropertyType             = pc.PropertyType;
                property.IsInherited              = pc.IsInherited;
                property.IsQueryProperty          = pc.IsQueryProperty;
                property.IsReadOnly               = pc.IsReadOnly;
                property.InheritEntityMappingName = pc.InheritEntityMappingName;
                //property.IsCompoundUnit = pc.IsCompoundUnit;
                property.Comment               = pc.Comment;
                property.CustomData            = pc.CustomData;
                property.IsContained           = pc.IsContained;
                property.IsFriendKey           = pc.IsFriendKey;
                property.IsIndexProperty       = pc.IsIndexProperty;
                property.IsIndexPropertyDesc   = pc.IsIndexPropertyDesc;
                property.IsInherited           = pc.IsInherited;
                property.IsLazyLoad            = pc.IsLazyLoad;
                property.IsNotNull             = pc.IsNotNull;
                property.IsPrimaryKey          = pc.IsPrimaryKey;
                property.IsQueryProperty       = pc.IsQueryProperty;
                property.IsReadOnly            = pc.IsReadOnly;
                property.IsRelationKey         = pc.IsRelationKey;
                property.IsSerializationIgnore = pc.IsSerializationIgnore;
                property.MappingName           = pc.MappingName;
                property.Name = pc.Name;
                property.PropertyMappingColumnType = pc.PropertyMappingColumnType;
                property.PropertyType      = pc.PropertyType;
                property.QueryOrderBy      = pc.QueryOrderBy;
                property.QueryType         = pc.QueryType;
                property.QueryWhere        = pc.QueryWhere;
                property.RelatedForeignKey = pc.RelatedForeignKey;
                property.RelatedType       = pc.RelatedType;
                property.RelationType      = pc.RelationType;
                property.SqlDefaultValue   = pc.SqlDefaultValue;
                property.SqlType           = pc.SqlType;

                if (pc.IsFriendKey)
                {
                    property.Attributes.Add(new FriendKeyDynAttribute(pc.RelatedType));
                }

                if (string.IsNullOrEmpty(pc.SqlType) == false)
                {
                    property.Attributes.Add(new SqlTypeDynAttribute(pc.SqlType));
                }

                if (pc.IsReadOnly)
                {
                    property.Attributes.Add(new ReadOnlyDynAttribute());
                }

                //if (pc.IsCompoundUnit)
                //    property.Attributes.Add(new CompoundUnitDynAttribute());

                if (pc.IsPrimaryKey)
                {
                    property.Attributes.Add(new PrimaryKeyDynAttribute());
                }

                if (pc.IsRelationKey)
                {
                    property.Attributes.Add(new RelationKeyDynAttribute(pc.RelatedForeignKey));
                }

                if (pc.IsIndexPropertyDesc)
                {
                    property.Attributes.Add(new PrimaryKeyDynAttribute());
                }

                if (pc.IsNotNull)
                {
                    property.Attributes.Add(new NotNullDynAttribute());
                }

                if (pc.IsSerializationIgnore)
                {
                    property.Attributes.Add(new SerializationIgnoreDynAttribute());
                }

                if (string.IsNullOrEmpty(pc.MappingName) == false)
                {
                    property.Attributes.Add(new MappingNameDynAttribute(pc.MappingName));
                }

                if (string.IsNullOrEmpty(pc.Comment) == false)
                {
                    property.Attributes.Add(new CommentDynAttribute(pc.Comment));
                }

                if (string.IsNullOrEmpty(pc.CustomData) == false)
                {
                    property.Attributes.Add(new CustomDataDynAttribute(pc.CustomData));
                }

                if (pc.IsQueryProperty)
                {
                    QueryType queryType = (QueryType)Enum.Parse(typeof(QueryType), pc.QueryType);

                    switch (queryType)
                    {
                    case QueryType.CustomQuery:
                        CustomQueryDynAttribute customQueryDynAttribute = new CustomQueryDynAttribute(pc.QueryWhere);
                        customQueryDynAttribute.OrderBy      = pc.QueryOrderBy;
                        customQueryDynAttribute.RelationType = pc.RelationType;
                        customQueryDynAttribute.LazyLoad     = pc.IsLazyLoad;
                        property.Attributes.Add(customQueryDynAttribute);
                        break;

                    case QueryType.FkQuery:
                        FkQueryDynAttribute fkQueryDynAttribute = new FkQueryDynAttribute(pc.RelatedForeignKey);     //zml ???
                        fkQueryDynAttribute.AdditionalWhere = pc.QueryWhere;
                        fkQueryDynAttribute.LazyLoad        = pc.IsLazyLoad;
                        fkQueryDynAttribute.OrderBy         = pc.QueryOrderBy;
                        property.Attributes.Add(fkQueryDynAttribute);

                        property.IsArray = true;
                        break;

                    case QueryType.FkReverseQuery:
                        FkReverseQueryDynAttribute fkReverseQueryDynAttribute = new FkReverseQueryDynAttribute(true);
                        fkReverseQueryDynAttribute.LazyLoad = pc.IsLazyLoad;
                        property.Attributes.Add(fkReverseQueryDynAttribute);
                        break;

                    case QueryType.ManyToManyQuery:
                        ManyToManyQueryDynAttribute manyToManyQueryDynAttribute = new ManyToManyQueryDynAttribute(pc.RelationType);
                        manyToManyQueryDynAttribute.AdditionalWhere = pc.QueryWhere;
                        manyToManyQueryDynAttribute.LazyLoad        = pc.IsLazyLoad;
                        manyToManyQueryDynAttribute.OrderBy         = pc.QueryOrderBy;
                        property.Attributes.Add(manyToManyQueryDynAttribute);

                        property.IsArray = true;
                        break;

                    case QueryType.PkQuery:
                        PkQueryDynAttribute pkQueryDynAttribute = new PkQueryDynAttribute();
                        pkQueryDynAttribute.LazyLoad = pc.IsLazyLoad;
                        property.Attributes.Add(pkQueryDynAttribute);
                        break;

                    case QueryType.PkReverseQuery:
                        PkReverseQueryDynAttribute pkReverseQueryDynAttribute = new PkReverseQueryDynAttribute(true);
                        pkReverseQueryDynAttribute.LazyLoad = pc.IsLazyLoad;
                        property.Attributes.Add(pkReverseQueryDynAttribute);
                        break;
                    }
                }

                if (pc.IsIndexProperty)
                {
                    IndexPropertyDynAttribute indexPropertyDynAttribute = new IndexPropertyDynAttribute(pc.IsIndexPropertyDesc);
                    property.Attributes.Add(indexPropertyDynAttribute);
                }

                if (property.IsQueryProperty)
                {
                    if (property.IsArray)
                    {
                        property.PropertyOriginalEntityType = property.PropertyType.Replace(nameSpace + ".", "").Replace("ArrayList", "");
                    }
                    else
                    {
                        property.PropertyOriginalEntityType = property.PropertyType.Replace(nameSpace + ".", "");
                    }
                }
                else
                {
                    property.PropertyOriginalEntityType = property.PropertyType;
                }


                et.AddProperty(property);
            }
            return(et);
        }