当前位置: 首页>>代码示例>>C#>>正文


C# ODataItem类代码示例

本文整理汇总了C#中ODataItem的典型用法代码示例。如果您正苦于以下问题:C# ODataItem类的具体用法?C# ODataItem怎么用?C# ODataItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ODataItem类属于命名空间,在下文中一共展示了ODataItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteNestedItems

        private static void WriteNestedItems(ODataItem[] nestedItemsToWrite, ODataAtomWriter writer)
        {
            foreach (ODataItem itemToWrite in nestedItemsToWrite)
            {
                ODataFeed feedToWrite = itemToWrite as ODataFeed;
                if (feedToWrite != null)
                {
                    writer.WriteStart(feedToWrite);
                }
                else
                {
                    ODataEntry entryToWrite = itemToWrite as ODataEntry;
                    if (entryToWrite != null)
                    {
                        writer.WriteStart(entryToWrite);
                    }
                    else
                    {
                        writer.WriteStart((ODataNavigationLink)itemToWrite);
                    }
                }
            }

            for (int count = 0; count < nestedItemsToWrite.Length; count++)
            {
                writer.WriteEnd();
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:28,代码来源:ODataAtomWriterEnumIntegrationTests.cs

示例2: WriteRequestWithoutModelAndValidatePayload

 private void WriteRequestWithoutModelAndValidatePayload(ODataItem[] nestedItemToWrite, string expectedPayload, bool setMetadataDocumentUri = true)
 {
     // without model, write request
     // 1. CreateEntityContainerElementContextUri(): no entitySetName --> no context uri is output.
     // 2. but odata.type will be output because of no model. JsonMinimalMetadataTypeNameOracle.GetEntryTypeNameForWriting method: // We only write entity type names in Json Light if it's more derived (different) from the expected type name.
     var stream = new MemoryStream();
     var outputContext = CreateAtomOutputContext(stream, null, false, null);
     var writer = new ODataAtomWriter(outputContext, null, null, nestedItemToWrite[0] is ODataFeed);
     WriteNestedItems(nestedItemToWrite, writer);
     ValidateWrittenPayload(stream, writer, expectedPayload);
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:11,代码来源:ODataAtomWriterEnumIntegrationTests.cs

示例3: GetWriterOutputForContentTypeAndKnobValue

        private string GetWriterOutputForContentTypeAndKnobValue(
            string contentType,
            bool autoComputePayloadMetadataInJson,
            ODataItem[] itemsToWrite,
            EdmModel edmModel,
            IEdmEntitySetBase edmEntitySet,
            EdmEntityType edmEntityType,
            string selectClause = null,
            string expandClause = null,
            string resourcePath = null,
            bool enableFullValidation = true)
        {
            MemoryStream outputStream = new MemoryStream();
            IODataResponseMessage message = new InMemoryMessage() { Stream = outputStream };
            message.SetHeader("Content-Type", contentType);
            ODataMessageWriterSettings settings = new ODataMessageWriterSettings()
            {
                AutoComputePayloadMetadataInJson = autoComputePayloadMetadataInJson,
                EnableFullValidation = enableFullValidation
            };

            var result = new ODataQueryOptionParser(edmModel, edmEntityType, edmEntitySet, new Dictionary<string, string> { { "$expand", expandClause }, { "$select", selectClause } }).ParseSelectAndExpand();

            ODataUri odataUri = new ODataUri()
            {
                ServiceRoot = new Uri("http://example.org/odata.svc"),
                SelectAndExpand = result
            };

            if (resourcePath != null)
            {
                Uri requestUri = new Uri("http://example.org/odata.svc/" + resourcePath);
                odataUri.RequestUri = requestUri;
                odataUri.Path = new ODataUriParser(edmModel, new Uri("http://example.org/odata.svc/"), requestUri).ParsePath();
            }

            settings.ODataUri = odataUri;

            string output;
            using (var messageWriter = new ODataMessageWriter(message, settings, edmModel))
            {
                int currentIdx = 0;

                if (itemsToWrite[currentIdx] is ODataFeed)
                {
                    ODataWriter writer = messageWriter.CreateODataFeedWriter(edmEntitySet, edmEntityType);
                    this.WriteFeed(writer, itemsToWrite, ref currentIdx);
                }
                else if (itemsToWrite[currentIdx] is ODataEntry)
                {
                    ODataWriter writer = messageWriter.CreateODataEntryWriter(edmEntitySet, edmEntityType);
                    this.WriteEntry(writer, itemsToWrite, ref currentIdx);
                }
                else
                {
                    Assert.True(false, "Top level item to write must be entry or feed.");
                }

                currentIdx.Should().Be(itemsToWrite.Length, "Invalid list of items to write.");

                outputStream.Seek(0, SeekOrigin.Begin);
                output = new StreamReader(outputStream).ReadToEnd();
            }

            return output;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:66,代码来源:FullPayloadValidateTests.cs

示例4: WritingNestedInlinecountTest

        public void WritingNestedInlinecountTest()
        {
            ODataFeed feed = new ODataFeed { Count = 1 };

            ODataItem[] itemsToWrite = new ODataItem[]
            {
                new ODataFeed(), 
                this.entryWithOnlyData1,
                this.containedCollectionNavLink,
                feed
            };

            string resourcePath = "EntitySet";
            string result = this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, Model, EntitySet, EntityType, null, null, resourcePath);

            string expectedPayload = "{" +
                                            "\"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet\"," +
                                            "\"value\":[" +
                                                "{" +
                                                    "\"ID\":101,\"Name\":\"Alice\"," +
                                                    "\"[email protected]\":\"http://example.org/odata.svc/$metadata#EntitySet(101)/ContainedCollectionNavProp\"," +
                                                    "\"[email protected]\":\"http://example.org/odata.svc/navigation\"," +
                                                    "\"[email protected]\":1," +
                                                    "\"ContainedCollectionNavProp\":[]" +
                                                "}" +
                                            "]" +
                                        "}";
            result.Should().Be(expectedPayload);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:29,代码来源:FullPayloadValidateTests.cs

示例5: WritingEntryExpandWithMixedCollectionAndNonCollectionContainedElementWithTypeCast

        public void WritingEntryExpandWithMixedCollectionAndNonCollectionContainedElementWithTypeCast()
        {
            ODataItem[] itemsToWrite = new ODataItem[]
            {
                this.entryWithOnlyData1,
                this.containedCollectionNavLink,
                new ODataFeed(), 
                this.entryWithOnlyData2,
                this.containedNavLink, 
                this.entryWithOnlyData3,
            };

            const string selectClause = "Namespace.DerivedType/ContainedCollectionNavProp";
            const string expandClause = "Namespace.DerivedType/ContainedCollectionNavProp($select=ContainedNavProp;$expand=ContainedNavProp)";
            string result = this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, Model, EntitySet, EntityType, selectClause, expandClause, "EntitySet(101)");

            string expectedPayload = "{\"@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet(Namespace.DerivedType/ContainedCollectionNavProp,Namespace.DerivedType/ContainedCollectionNavProp(ContainedNavProp))/$entity\"," +
                                        "\"ID\":101,\"Name\":\"Alice\"," +
                                        "\"[email protected]\":\"http://example.org/odata.svc/$metadata#EntitySet(101)/Namespace.DerivedType/ContainedCollectionNavProp(ContainedNavProp)\"," +
                                        "\"[email protected]\":\"http://example.org/odata.svc/navigation\"," +
                                        "\"ContainedCollectionNavProp\":" +
                                            "[" +
                                                "{" +
                                                    "\"ID\":102,\"Name\":\"Bob\"," +
                                                    "\"[email protected]\":\"http://example.org/odata.svc/$metadata#EntitySet(101)/Namespace.DerivedType/ContainedCollectionNavProp(102)/ContainedNavProp/$entity\"," +
                                                    "\"ContainedNavProp\":" +
                                                    "{" +
                                                        "\"ID\":103,\"Name\":\"Charlie\"" +
                                                    "}" +
                                                "}" +
                                            "]" +
                                        "}";
            result.Should().Be(expectedPayload);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:34,代码来源:FullPayloadValidateTests.cs

示例6: WritingTopLevelContainedEntryWithTypeCast

        public void WritingTopLevelContainedEntryWithTypeCast()
        {
            ODataItem[] itemsToWrite = new ODataItem[]
            {
                this.entryWithOnlyData2
            };

            IEdmNavigationProperty containedNavProp = EntityType.FindProperty("ContainedNavProp") as IEdmNavigationProperty;
            IEdmEntitySetBase contianedEntitySet = EntitySet.FindNavigationTarget(containedNavProp) as IEdmEntitySetBase;
            string resourcePath = "EntitySet(123)/ContainedNavProp/Namespace.DerivedType";
            string result = this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, Model, contianedEntitySet, DerivedType, null, null, resourcePath);

            string expectedPayload = "{\"" +
                                            "@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet(123)/ContainedNavProp/Namespace.DerivedType/$entity\"," +
                                            "\"ID\":102,\"Name\":\"Bob\"" +
                                        "}";
            result.Should().Be(expectedPayload);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:18,代码来源:FullPayloadValidateTests.cs

示例7: DeltaFeedScope

            /// <summary>
            /// Constructor to create a new feed scope.
            /// </summary>
            /// <param name="item">The feed for the new scope.</param>
            /// <param name="navigationSource">The navigation source we are going to write entities for.</param>
            /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
            /// <param name="selectedProperties">The selected properties of this scope.</param>
            /// <param name="odataUri">The ODataUri info of this scope.</param>
            protected DeltaFeedScope(ODataItem item, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri)
                : base(WriterState.DeltaFeed, item, navigationSource, entityType, selectedProperties, odataUri)
            {
                Debug.Assert(item != null, "item != null");

                var feed = item as ODataDeltaFeed;
                Debug.Assert(feed != null, "feed must be DeltaFeed.");

                this.serializationInfo = feed.SerializationInfo;
            }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:18,代码来源:ODataJsonLightDeltaWriter.cs

示例8: DeltaEntryScope

            /// <summary>
            /// Constructor to create a new entry scope.
            /// </summary>
            /// <param name="state">The writer state of this scope.</param>
            /// <param name="entry">The entry for the new scope.</param>
            /// <param name="serializationInfo">The serialization info for the current entry.</param>
            /// <param name="navigationSource">The navigation source we are going to write entities for.</param>
            /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
            /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param>
            /// <param name="selectedProperties">The selected properties of this scope.</param>
            /// <param name="odataUri">The ODataUri info of this scope.</param>
            protected DeltaEntryScope(WriterState state, ODataItem entry, ODataFeedAndEntrySerializationInfo serializationInfo, IEdmNavigationSource navigationSource, IEdmEntityType entityType, ODataWriterBehavior writerBehavior, SelectedPropertiesNode selectedProperties, ODataUri odataUri)
                : base(state, entry, navigationSource, entityType, selectedProperties, odataUri)
            {
                Debug.Assert(entry != null, "entry != null");
                Debug.Assert(
                    state == WriterState.DeltaEntry && entry is ODataEntry ||
                    state == WriterState.DeltaDeletedEntry && entry is ODataDeltaDeletedEntry,
                    "entry must be either DeltaEntry or DeltaDeletedEntry.");
                Debug.Assert(writerBehavior != null, "writerBehavior != null");

                this.duplicatePropertyNamesChecker = new DuplicatePropertyNamesChecker(writerBehavior.AllowDuplicatePropertyNames, /*writingResponse*/ true);
                this.serializationInfo = serializationInfo;
            }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:24,代码来源:ODataJsonLightDeltaWriter.cs

示例9: Scope

 /// <summary>
 /// Constructor creating a new writer scope.
 /// </summary>
 /// <param name="state">The writer state of this scope.</param>
 /// <param name="item">The item attached to this scope.</param>
 /// <param name="navigationSource">The navigation source we are going to write entities for.</param>
 /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
 /// <param name="selectedProperties">The selected properties of this scope.</param>
 /// <param name="odataUri">The ODataUri info of this scope.</param>
 internal Scope(WriterState state, ODataItem item, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri)
 {
     this.state = state;
     this.item = item;
     this.EntityType = entityType;
     this.NavigationSource = navigationSource;
     this.selectedProperties = selectedProperties;
     this.odataUri = odataUri;
 }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:18,代码来源:ODataJsonLightDeltaWriter.cs

示例10: GetLinkSerializationInfo

        /// <summary>
        /// Gets the serialization info for the given delta link.
        /// </summary>
        /// <param name="item">The entry to get the serialization info for.</param>
        /// <returns>The serialization info for the given entry.</returns>
        private ODataDeltaSerializationInfo GetLinkSerializationInfo(ODataItem item)
        {
            Debug.Assert(item != null, "item != null");

            ODataDeltaSerializationInfo serializationInfo = null;

            var deltaLink = item as ODataDeltaLink;
            if (deltaLink != null)
            {
                serializationInfo = deltaLink.SerializationInfo;
            }

            var deltaDeletedLink = item as ODataDeltaDeletedLink;
            if (deltaDeletedLink != null)
            {
                serializationInfo = deltaDeletedLink.SerializationInfo;
            }

            return serializationInfo ?? this.GetParentFeedSerializationInfo();
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:25,代码来源:ODataJsonLightDeltaWriter.cs

示例11: GetEntrySerializationInfo

        /// <summary>
        /// Gets the serialization info for the given delta entry.
        /// </summary>
        /// <param name="item">The entry to get the serialization info for.</param>
        /// <returns>The serialization info for the given entry.</returns>
        private ODataFeedAndEntrySerializationInfo GetEntrySerializationInfo(ODataItem item)
        {
            Debug.Assert(item != null, "item != null");

            ODataFeedAndEntrySerializationInfo serializationInfo = null;

            var entry = item as ODataEntry;
            if (entry != null)
            {
                serializationInfo = entry.SerializationInfo;
            }

            var deltaDeletedEntry = item as ODataDeltaDeletedEntry;
            if (deltaDeletedEntry != null)
            {
                serializationInfo = DeltaConverter.ToFeedAndEntrySerializationInfo(deltaDeletedEntry.SerializationInfo);
            }

            if (serializationInfo == null)
            {
                serializationInfo = DeltaConverter.ToFeedAndEntrySerializationInfo(this.GetParentFeedSerializationInfo());
            }

            return serializationInfo;
        }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:30,代码来源:ODataJsonLightDeltaWriter.cs

示例12: CreateDeltaLinkScope

 /// <summary>
 /// Create a new delta link scope.
 /// </summary>
 /// <param name="state">The writer state of the scope to create.</param>
 /// <param name="link">The link for the new scope.</param>
 /// <param name="navigationSource">The navigation source we are going to write entities for.</param>
 /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
 /// <param name="selectedProperties">The selected properties of this scope.</param>
 /// <param name="odataUri">The ODataUri info of this scope.</param>
 /// <returns>The newly create scope.</returns>
 private DeltaLinkScope CreateDeltaLinkScope(WriterState state, ODataItem link, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri)
 {
     return new JsonLightDeltaLinkScope(
         state,
         link,
         this.GetLinkSerializationInfo(link),
         navigationSource,
         entityType,
         this.jsonLightOutputContext.MessageWriterSettings.WriterBehavior,
         selectedProperties,
         odataUri);
 }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:22,代码来源:ODataJsonLightDeltaWriter.cs

示例13: CreateDeltaFeedScope

 /// <summary>
 /// Create a new delta feed scope.
 /// </summary>
 /// <param name="feed">The feed for the new scope.</param>
 /// <param name="navigationSource">The navigation source we are going to write entities for.</param>
 /// <param name="entityType">The entity type for the entries in the feed to be written (or null if the entity set base type should be used).</param>
 /// <param name="selectedProperties">The selected properties of this scope.</param>
 /// <param name="odataUri">The ODataUri info of this scope.</param>
 /// <returns>The newly create scope.</returns>
 private DeltaFeedScope CreateDeltaFeedScope(ODataItem feed, IEdmNavigationSource navigationSource, IEdmEntityType entityType, SelectedPropertiesNode selectedProperties, ODataUri odataUri)
 {
     return new JsonLightDeltaFeedScope(feed, navigationSource, entityType, selectedProperties, odataUri);
 }
开发者ID:spawnadv,项目名称:msgraphodata.net,代码行数:13,代码来源:ODataJsonLightDeltaWriter.cs

示例14: WriteEntry

        private void WriteEntry(ODataWriter writer, ODataItem[] itemsToWrite, ref int currentIdx)
        {
            if (currentIdx < itemsToWrite.Length)
            {
                ODataEntry entry = (ODataEntry)itemsToWrite[currentIdx++];
                writer.WriteStart(entry);
                while (currentIdx < itemsToWrite.Length)
                {
                    if (itemsToWrite[currentIdx] is ODataNavigationLink)
                    {
                        this.WriteLink(writer, itemsToWrite, ref currentIdx);
                    }
                    else if (itemsToWrite[currentIdx] is ODataNavigationLinkEnd)
                    {
                        currentIdx++;
                        writer.WriteEnd();
                        return;
                    }
                    else
                    {
                        break;
                    }
                }

                writer.WriteEnd();
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:27,代码来源:FullPayloadValidateTests.cs

示例15: WriteLink

        private void WriteLink(ODataWriter writer, ODataItem[] itemsToWrite, ref int currentIdx)
        {
            if (currentIdx < itemsToWrite.Length)
            {
                ODataNavigationLink link = (ODataNavigationLink)itemsToWrite[currentIdx++];
                writer.WriteStart(link);
                if (currentIdx < itemsToWrite.Length)
                {
                    if (itemsToWrite[currentIdx] is ODataEntry)
                    {
                        this.WriteEntry(writer, itemsToWrite, ref currentIdx);
                    }
                    else if (itemsToWrite[currentIdx] is ODataFeed)
                    {
                        this.WriteFeed(writer, itemsToWrite, ref currentIdx);
                    }
                }

                writer.WriteEnd();
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:21,代码来源:FullPayloadValidateTests.cs


注:本文中的ODataItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。