Пример #1
0
        private void GetPathContext()
        {
            if (Path != null)
            {
                IEdmProperty       property;
                IEdmStructuredType structuredType;
                string             name;
                EdmLibHelpers.GetPropertyAndStructuredTypeFromPath(
                    Path.Segments,
                    out property,
                    out structuredType,
                    out name);

                TargetProperty       = property;
                TargetStructuredType = structuredType;
                TargetName           = name;
            }
            else
            {
                TargetStructuredType = ElementType as IEdmStructuredType;
            }
        }
Пример #2
0
        private static IEdmEntityTypeReference GetTypeReference(IEdmModel model, IEdmEntityType edmType, object value)
        {
            if (model == null || edmType == null || value == null)
            {
                return(null);
            }

            IEdmObject edmObject = value as IEdmEntityObject;

            if (edmObject != null)
            {
                IEdmTypeReference edmTypeReference = edmObject.GetEdmType();
                return(edmTypeReference.AsEntity());
            }

            IEdmTypeReference reference = EdmLibHelpers.GetEdmTypeReference(model, value.GetType());

            if (reference != null && reference.Definition.IsOrInheritsFrom(edmType))
            {
                return((IEdmEntityTypeReference)reference);
            }

            return(null);
        }
Пример #3
0
 /// <inheritdoc/>
 public IEdmTypeReference GetEdmType()
 {
     return(EdmLibHelpers.ToEdmTypeReference(_actualEdmType, IsNullable));
 }
Пример #4
0
        /// <summary>
        /// Determine if the
        /// </summary>
        /// <param name="responseValue">The response value.</param>
        /// <param name="singleResultCollection">The content as SingleResult.Queryable.</param>
        /// <param name="actionDescriptor">The action context, i.e. action and controller name.</param>
        /// <param name="modelFunction">A function to get the model.</param>
        /// <param name="path">The OData path.</param>
        /// <returns></returns>
        private static bool ContainsAutoSelectExpandProperty(
            object responseValue,
            IQueryable singleResultCollection,
            IWebApiActionDescriptor actionDescriptor,
            Func <Type, IEdmModel> modelFunction,
            ODataPath path)
        {
            Type elementClrType = GetElementType(responseValue, singleResultCollection, actionDescriptor);

            IEdmModel model = modelFunction(elementClrType);

            if (model == null)
            {
                throw Error.InvalidOperation(SRResources.QueryGetModelMustNotReturnNull);
            }

            IEdmType           edmType        = model.GetTypeMappingCache().GetEdmType(elementClrType, model)?.Definition;
            IEdmEntityType     baseEntityType = edmType as IEdmEntityType;
            IEdmStructuredType structuredType = edmType as IEdmStructuredType;
            IEdmProperty       property       = null;

            if (path != null)
            {
                string name;
                EdmLibHelpers.GetPropertyAndStructuredTypeFromPath(path.Segments, out property,
                                                                   out structuredType,
                                                                   out name);
            }

            if (baseEntityType != null)
            {
                List <IEdmEntityType> entityTypes = new List <IEdmEntityType>();
                entityTypes.Add(baseEntityType);
                entityTypes.AddRange(EdmLibHelpers.GetAllDerivedEntityTypes(baseEntityType, model));
                foreach (var entityType in entityTypes)
                {
                    IEnumerable <IEdmNavigationProperty> navigationProperties = entityType == baseEntityType
                        ? entityType.NavigationProperties()
                        : entityType.DeclaredNavigationProperties();

                    if (navigationProperties != null)
                    {
                        if (navigationProperties.Any(
                                navigationProperty =>
                                EdmLibHelpers.IsAutoExpand(navigationProperty, property, entityType, model)))
                        {
                            return(true);
                        }
                    }

                    IEnumerable <IEdmStructuralProperty> properties = entityType == baseEntityType
                        ? entityType.StructuralProperties()
                        : entityType.DeclaredStructuralProperties();

                    if (properties != null)
                    {
                        foreach (var edmProperty in properties)
                        {
                            if (EdmLibHelpers.IsAutoSelect(edmProperty, property, entityType, model))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            else if (structuredType != null)
            {
                IEnumerable <IEdmStructuralProperty> properties = structuredType.StructuralProperties();
                if (properties != null)
                {
                    foreach (var edmProperty in properties)
                    {
                        if (EdmLibHelpers.IsAutoSelect(edmProperty, property, structuredType, model))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }