/// <summary> Replaces one registered entity with extended version. </summary>
        /// <param name="replacedType">The entity type to be replaced.</param>
        /// <param name="replacementEntityType">The new replacing entity type.</param>
        /// <remarks><para>
        /// This method provides a way to extend entities defined in independently built modules.
        /// The other use is to integrate the independently developed modules, so that the tables in database
        /// coming from different modules can actually reference each other through foreign keys.
        /// If the replacement type is not registered with any module, it is placed in the module of the type being replace.
        /// </para>
        /// </remarks>
        public void ReplaceEntity(Type replacedType, Type replacementEntityType)
        {
            CheckNotClosed();
            Util.Check(replacedType.IsInterface, "Invalid type: {0}; expected Entity interface.", replacedType);
            Util.Check(replacementEntityType.IsInterface, "Invalid type: {0}; expected Entity interface.",
                       replacementEntityType);
            Util.Check(replacedType.IsAssignableFrom(replacementEntityType),
                       "Invalid entity replacement type ({0}), must be derived from type being replaced ({1})", replacementEntityType.Name, replacedType.Name);
            var replInfo = new EntityReplacementInfo()
            {
                ReplacedType = replacedType, NewType = replacementEntityType
            };

            Replacements.Add(replInfo);
        }
示例#2
0
        /// <summary> Replaces one registered entity with extended version. </summary>
        /// <param name="replacedType">The entity type to be replaced.</param>
        /// <param name="replacementEntityType">The new replacing entity type.</param>
        /// <remarks><para>
        /// This method provides a way to extend entities defined in independently built modules.
        /// The other use is to integrate the independently developed modules, so that the tables in database
        /// coming from different modules can actually reference each other through foreign keys.
        /// If the replacement type is not registered with any module, it is placed in the module of the type being replace.
        /// </para>
        /// </remarks>
        public void ReplaceEntity(Type replacedType, Type replacementEntityType)
        {
            Util.Check(replacedType.IsInterface, "Invalid type: {0}; expected Entity interface.", replacedType);
            Util.Check(replacementEntityType.IsInterface, "Invalid type: {0}; expected Entity interface.", replacementEntityType);
            //Unless the type being replaced is an empty stub, then check that new type is compatible with the old type
            var oldTypeProps = replacedType.GetAllProperties();

            if (oldTypeProps.Count > 0) //it is not an empty stub
            {
                Util.Check(replacedType.IsAssignableFrom(replacementEntityType),
                           "The replacing type ({0}) must be a subtype of the type being replaced ({1}). ", replacementEntityType, replacedType);
            }
            var replInfo = new EntityReplacementInfo()
            {
                ReplacedType = replacedType, NewType = replacementEntityType
            };

            Replacements.Add(replInfo);
        }