示例#1
0
        /// <summary>
        /// Computes the differences between two DataModels.
        /// </summary>
        /// <param name="originalModel">The original model.</param>
        /// <param name="newModel">The new model.</param>
        /// <returns>Collection of DataModel differences</returns>
        internal static ModuleCollectionChange ComputeDifferences(DataModel originalModel, DataModel newModel)
        {
            DataModelModuleCollection originalModules = originalModel.Modules;
            DataModelModuleCollection newModules      = newModel.Modules;

            // All the comparisons are based on data model item Id values. It is thus important
            // to make all Id properties on the data model items internal so that once an item
            // is assigned an Id, that cannot change in its entire life.
            // Assumption: Earlier validations ensure that all the items are present within this
            // model and are not shared between data models. For example, there is no possibility
            // that an association present in this data model has one of its navigation properties
            // in this model but the other navigation property in some other model. Likewise, it
            // should not be possible for two data models to reach the same resource type while
            // enumerating the hosted types. An example source code is shown below. Here, it may
            // be possible to reach 'Resource' resource type from module2 but its Parent property
            // points to module1.
            //var module1 = new ZentityContext().Core.Modules[0];
            //var module2 = new ZentityContext().Core.Modules[0];
            //module1.ResourceTypes.Add(module2.ResourceTypes["Resource"]);

            ModuleCollectionChange changes = new ModuleCollectionChange();

            CompareDataModelModules(changes, originalModules, newModules);

            CompareResourceTypes(changes, originalModules, newModules);

            CompareScalarProperties(changes, originalModules, newModules);

            CompareNavigationProperties(changes, originalModules, newModules);

            CompareAssociations(changes, originalModules, newModules);

            return(changes);
        }