示例#1
0
        /// <summary>
        /// Initializes the EPM annotation with EPM information from the specified type.
        /// </summary>
        /// <param name="definingEntityType">Entity type to use the EPM infromation from.</param>
        /// <param name="affectedEntityType">Entity type for this the EPM information is being built.</param>
        internal void BuildEpmForType(IEdmEntityType definingEntityType, IEdmEntityType affectedEntityType)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(definingEntityType != null, "definingEntityType != null");
            Debug.Assert(affectedEntityType != null, "affectedEntityType != null");

            if (definingEntityType.BaseType != null)
            {
                this.BuildEpmForType(definingEntityType.BaseEntityType(), affectedEntityType);
            }

            ODataEntityPropertyMappingCollection mappingsForType = this.model.GetEntityPropertyMappings(definingEntityType);

            if (mappingsForType == null)
            {
                return;
            }

            foreach (EntityPropertyMappingAttribute mapping in mappingsForType)
            {
                this.epmSourceTree.Add(new EntityPropertyMappingInfo(mapping, definingEntityType, affectedEntityType));

                if (definingEntityType == affectedEntityType)
                {
                    if (!PropertyExistsOnType(affectedEntityType, mapping))
                    {
                        this.MappingsForInheritedProperties.Add(mapping);
                        this.MappingsForDeclaredProperties.Remove(mapping);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mappings">The EPM mappings to create the cache for.</param>
        /// <param name="model">The EDM model.</param>
        /// <param name="totalMappingCount">The total number of entity property mappings
        /// for the entity type that this cache is created for (on the type itself and all its base types).</param>
        internal ODataEntityPropertyMappingCache(ODataEntityPropertyMappingCollection mappings, IEdmModel model, int totalMappingCount)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(model.IsUserModel(), "model.IsUserModel()");

            this.mappings          = mappings;
            this.model             = model;
            this.totalMappingCount = totalMappingCount;

            // Note that we new up everything here eagerly because we will only create the EPM annotation for types
            // for which we know for sure that they have EPM and thus we will need all of these anyway.
            this.mappingsForInheritedProperties = new List <EntityPropertyMappingAttribute>();
            this.mappingsForDeclaredProperties  = mappings == null
                ? new List <EntityPropertyMappingAttribute>()
                : new List <EntityPropertyMappingAttribute>(mappings);
            this.epmTargetTree = new EpmTargetTree();
            this.epmSourceTree = new EpmSourceTree(this.epmTargetTree);
        }
示例#3
0
        /// <summary>
        /// Checks whether the current cache is dirty with respect to the <paramref name="propertyMappings"/>.
        /// </summary>
        /// <param name="propertyMappings">The EPM mappings to check this cache against.</param>
        /// <returns>true if the <paramref name="propertyMappings"/> are not the same as the ones the cache has been created for (or have changed).</returns>
        internal bool IsDirty(ODataEntityPropertyMappingCollection propertyMappings)
        {
            DebugUtils.CheckNoExternalCallers();

            // NOTE: we only allow adding more mappings to an existing collection; so if the
            // references of the collections are the same and the counts are the same there has been no change.
            if (this.mappings == null && propertyMappings == null)
            {
                return(false);
            }

            if (!object.ReferenceEquals(this.mappings, propertyMappings))
            {
                return(true);
            }

            return(this.mappings.Count != propertyMappings.Count);
        }