コード例 #1
0
        public IActionResult Get()
        {
            IEdmCollectionType collectionType;

            ODataPath oDataPath = Request.ODataFeature().Path;
            IEdmType  edmType   = oDataPath.Segments.First().EdmType;

            IEdmEntityType entityType;

            if (edmType is IEdmCollectionType ct)
            {
                collectionType = ct;
                entityType     = collectionType.ElementType.Definition as IEdmEntityType;
            }
            else
            {
                throw new Exception($"Unexpected EDM type '{edmType?.GetType()}'.");
            }

            IEnumerable <IEdmEntityObject> entityObjects = this.GetData(entityType);

            IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType);

            StreamingEdmEntityObjectCollection collection = new StreamingEdmEntityObjectCollection
                                                                (collectionTypeReference
                                                                , entityObjects
                                                                );

            //
            // Return a collection type.
            //
            return(Ok(collection));
        }
コード例 #2
0
ファイル: EdmTypeExtensions.cs プロジェクト: tvdburgt/WebApi
 /// <summary>
 /// Method to determine whether the current type is containing a Delta Feed
 /// </summary>
 /// <param name="type">IEdmType to be compared</param>
 /// <returns>True or False if type is same as <see cref="EdmDeltaCollectionType"/></returns>
 public static bool IsDeltaFeed(this IEdmType type)
 {
     if (type == null)
     {
         throw Error.ArgumentNull("type");
     }
     return(type.GetType() == typeof(EdmDeltaCollectionType));
 }
コード例 #3
0
        /// <summary>
        /// Method to determine whether the current type is a Delta resource set.
        /// </summary>
        /// <param name="type">IEdmType to be compared</param>
        /// <returns>True or False if type is same as <see cref="EdmDeltaCollectionType"/></returns>
        public static bool IsDeltaResourceSet(this IEdmType type)
        {
            if (type == null)
            {
                throw Error.ArgumentNull(nameof(type));
            }

            return(type.GetType() == typeof(EdmDeltaCollectionType));
        }
コード例 #4
0
            //-----------------------------------------------------------------------------------------------------------------------------------------------------
            private Type TranslateEdmTypeToClrType(IEdmModel model, IEdmType edmType)
            {
                var annotation = model.GetAnnotationValue<ClrTypeAnnotation>(edmType);

                if ( annotation != null )
                {
                    return annotation.ClrType;
                }

                var entityType = (edmType as IEdmEntityType);

                if ( entityType != null )
                {
                    return base.Context.Factory.FindDynamicType(new EdmEntityTypeKey(model, entityType));
                }

                var collectionType = (edmType as IEdmCollectionType);

                if ( collectionType != null )
                {
                    var elementClrType = TranslateEdmTypeToClrType(model, collectionType.ElementType.Definition);
                    return typeof (DataServiceCollection<>).MakeGenericType(elementClrType);
                }

                var primitiveType = (edmType as IEdmPrimitiveType);

                if ( primitiveType != null )
                {
                    return s_BuiltInTypesMapping[primitiveType];
                }

                throw new Exception("Could not determine CLR type for EDM type: " + edmType.FullTypeName() + " {" + edmType.GetType().Name + "}");
            }