/// <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);
                    }
                }
            }
        }
Exemplo n.º 2
0
 internal bool IsDirty(ODataEntityPropertyMappingCollection propertyMappings)
 {
     if ((this.mappings == null) && (propertyMappings == null))
     {
         return(false);
     }
     return(!object.ReferenceEquals(this.mappings, propertyMappings) || (this.mappings.Count != propertyMappings.Count));
 }
Exemplo n.º 3
0
 internal ODataEntityPropertyMappingCache(ODataEntityPropertyMappingCollection mappings, IEdmModel model, int totalMappingCount)
 {
     this.mappings          = mappings;
     this.model             = model;
     this.totalMappingCount = totalMappingCount;
     this.mappingsForInheritedProperties = new List <EntityPropertyMappingAttribute>();
     this.mappingsForDeclaredProperties  = (mappings == null) ? new List <EntityPropertyMappingAttribute>() : new List <EntityPropertyMappingAttribute>(mappings);
     this.epmTargetTree = new Microsoft.Data.OData.Metadata.EpmTargetTree();
     this.epmSourceTree = new Microsoft.Data.OData.Metadata.EpmSourceTree(this.epmTargetTree);
 }
Exemplo n.º 4
0
        private static ODataEntityPropertyMappingCache EnsureEpmCacheInternal(IEdmModel model, IEdmEntityType entityType, int maxMappingCount, out bool cacheModified)
        {
            cacheModified = false;
            if (entityType == null)
            {
                return(null);
            }
            IEdmEntityType type = entityType.BaseEntityType();
            ODataEntityPropertyMappingCache baseCache = null;

            if (type != null)
            {
                baseCache = EnsureEpmCacheInternal(model, type, maxMappingCount, out cacheModified);
            }
            ODataEntityPropertyMappingCache epmCache = model.GetEpmCache(entityType);

            if (model.HasOwnOrInheritedEpm(entityType))
            {
                ODataEntityPropertyMappingCollection entityPropertyMappings = model.GetEntityPropertyMappings(entityType);
                if (!(((epmCache == null) || cacheModified) || epmCache.IsDirty(entityPropertyMappings)))
                {
                    return(epmCache);
                }
                cacheModified = true;
                int totalMappingCount = ValidationUtils.ValidateTotalEntityPropertyMappingCount(baseCache, entityPropertyMappings, maxMappingCount);
                epmCache = new ODataEntityPropertyMappingCache(entityPropertyMappings, model, totalMappingCount);
                try
                {
                    epmCache.BuildEpmForType(entityType, entityType);
                    epmCache.EpmSourceTree.Validate(entityType);
                    model.SetAnnotationValue <ODataEntityPropertyMappingCache>(entityType, epmCache);
                    return(epmCache);
                }
                catch
                {
                    model.RemoveEpmCache(entityType);
                    throw;
                }
            }
            if (epmCache != null)
            {
                cacheModified = true;
                model.RemoveEpmCache(entityType);
            }
            return(epmCache);
        }
Exemplo n.º 5
0
        private static void LoadEpmAnnotations(IEdmModel model, IEdmEntityType entityType)
        {
            string typeName = entityType.ODataFullName();
            ODataEntityPropertyMappingCollection mappings = new ODataEntityPropertyMappingCollection();

            model.LoadEpmAnnotations(entityType, mappings, typeName, null);
            IEnumerable <IEdmProperty> declaredProperties = entityType.DeclaredProperties;

            if (declaredProperties != null)
            {
                foreach (IEdmProperty property in declaredProperties)
                {
                    model.LoadEpmAnnotations(property, mappings, typeName, property);
                }
            }
            model.SetAnnotationValue <ODataEntityPropertyMappingCollection>(entityType, mappings);
        }
        /// <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);
        }
        /// <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);
        }
Exemplo n.º 8
0
        internal void BuildEpmForType(IEdmEntityType definingEntityType, IEdmEntityType affectedEntityType)
        {
            if (definingEntityType.BaseType != null)
            {
                this.BuildEpmForType(definingEntityType.BaseEntityType(), affectedEntityType);
            }
            ODataEntityPropertyMappingCollection entityPropertyMappings = this.model.GetEntityPropertyMappings(definingEntityType);

            if (entityPropertyMappings != null)
            {
                foreach (EntityPropertyMappingAttribute attribute in entityPropertyMappings)
                {
                    this.epmSourceTree.Add(new EntityPropertyMappingInfo(attribute, definingEntityType, affectedEntityType));
                    if ((definingEntityType == affectedEntityType) && !PropertyExistsOnType(affectedEntityType, attribute))
                    {
                        this.MappingsForInheritedProperties.Add(attribute);
                        this.MappingsForDeclaredProperties.Remove(attribute);
                    }
                }
            }
        }
Exemplo n.º 9
0
        private static void LoadEpmAnnotations(this IEdmModel model, IEdmElement annotatable, ODataEntityPropertyMappingCollection mappings, string typeName, IEdmProperty property)
        {
            IEnumerable <EpmAnnotationValues> enumerable = model.ParseSerializableEpmAnnotations(annotatable, typeName, property);

            if (enumerable != null)
            {
                foreach (EpmAnnotationValues values in enumerable)
                {
                    EntityPropertyMappingAttribute mapping = ValidateAnnotationValues(values, typeName, property);
                    mappings.Add(mapping);
                }
            }
        }