當前位置: 首頁>>代碼示例>>C#>>正文


C# Core.ODataNavigationLink類代碼示例

本文整理匯總了C#中Microsoft.OData.Core.ODataNavigationLink的典型用法代碼示例。如果您正苦於以下問題:C# ODataNavigationLink類的具體用法?C# ODataNavigationLink怎麽用?C# ODataNavigationLink使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ODataNavigationLink類屬於Microsoft.OData.Core命名空間,在下文中一共展示了ODataNavigationLink類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InitTest

        public void InitTest()
        {
            this.navigationLink = new ODataNavigationLink();

            var entry = new ODataEntry
            {
                TypeName = "ns.DerivedType",
                Properties = new[]
                {
                    new ODataProperty{Name = "Id", Value = 1, SerializationInfo = new ODataPropertySerializationInfo{PropertyKind = ODataPropertyKind.Key}},
                    new ODataProperty{Name = "Name", Value = "Bob", SerializationInfo = new ODataPropertySerializationInfo{PropertyKind = ODataPropertyKind.ETag}}
                }
            };

            var serializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "Set", NavigationSourceEntityTypeName = "ns.BaseType", ExpectedTypeName = "ns.BaseType" };
            var typeContext = ODataFeedAndEntryTypeContext.Create(serializationInfo, null, null, null, EdmCoreModel.Instance, true);
            var metadataContext = new TestMetadataContext();
            var entryMetadataContext = ODataEntryMetadataContext.Create(entry, typeContext, serializationInfo, null, metadataContext, SelectedPropertiesNode.EntireSubtree);
            var metadataBuilder = new ODataConventionalEntityMetadataBuilder(entryMetadataContext, metadataContext, new ODataConventionalUriBuilder(ServiceUri, UrlConvention.CreateWithExplicitValue(false)));
            this.navigationLinkWithFullBuilder = new ODataNavigationLink { Name = "NavProp" };
            this.navigationLinkWithFullBuilder.MetadataBuilder = metadataBuilder;

            this.navigationLinkWithNoOpBuilder = new ODataNavigationLink { Name = "NavProp" };
            this.navigationLinkWithNoOpBuilder.MetadataBuilder = new NoOpEntityMetadataBuilder(entry);

            this.navigationLinkWithNullBuilder = new ODataNavigationLink { Name = "NavProp" };
            this.navigationLinkWithNullBuilder.MetadataBuilder = ODataEntityMetadataBuilder.Null;
        }
開發者ID:rossjempson,項目名稱:odata.net,代碼行數:28,代碼來源:ODataNavigationLinkTests.cs

示例2: CreateLink

 /// <summary>
 /// Creates the materializer link with a feed.
 /// </summary>
 /// <param name="link">The link.</param>
 /// <param name="feed">The feed.</param>
 /// <returns>The materializer link.</returns>
 public static MaterializerNavigationLink CreateLink(ODataNavigationLink link, ODataFeed feed)
 {
     Debug.Assert(link.GetAnnotation<MaterializerNavigationLink>() == null, "there should be no MaterializerNavigationLink annotation on the feed link yet");
     MaterializerNavigationLink materializedNavigationLink = new MaterializerNavigationLink(link, feed);
     link.SetAnnotation<MaterializerNavigationLink>(materializedNavigationLink);
     return materializedNavigationLink;
 }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:13,代碼來源:MaterializerNavigationLink.cs

示例3: DefaultValuesTest

 public void DefaultValuesTest()
 {
     ODataNavigationLink navigationLink = new ODataNavigationLink();
     this.Assert.IsNull(navigationLink.Name, "Expected null default value for property 'Name'.");
     this.Assert.IsNull(navigationLink.Url, "Expected null default value for property 'Url'.");
     this.Assert.IsNull(navigationLink.IsCollection, "Expected null default value for property 'IsCollection'.");
 }
開發者ID:AlineGuan,項目名稱:odata.net,代碼行數:7,代碼來源:ODataNavigationLinkTests.cs

示例4: MaterializerNavigationLink

 /// <summary>
 /// Prevents a default instance of the <see cref="MaterializerNavigationLink"/> struct from being created.
 /// </summary>
 /// <param name="link">The link.</param>
 /// <param name="materializedFeedOrEntry">Value of the link.</param>
 private MaterializerNavigationLink(ODataNavigationLink link, object materializedFeedOrEntry)
 {
     Debug.Assert(link != null, "link != null");
     Debug.Assert(materializedFeedOrEntry != null, "materializedFeedOrEntry != null");
     Debug.Assert(materializedFeedOrEntry is MaterializerEntry || materializedFeedOrEntry is ODataFeed, "must be feed or entry");
     this.link = link;
     this.feedOrEntry = materializedFeedOrEntry;
 }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:13,代碼來源:MaterializerNavigationLink.cs

示例5: DataServiceODataWriterNavigationLinkArgs

 /// <summary>
 /// Creates a new instance of DataServiceODataWriterNavigationLinkArgs.
 /// </summary>
 /// <param name="navigationLink">Instance of ODataNavigationLink.</param>
 /// <param name="operationContext">Instance of DataServiceOperationContext.</param>
 public DataServiceODataWriterNavigationLinkArgs(
     ODataNavigationLink navigationLink,
     DataServiceOperationContext operationContext)
 {
     WebUtil.CheckArgumentNull(navigationLink, "navigationLink != null");
     Debug.Assert(operationContext != null, "navigationLink != null");
     this.NavigationLink = navigationLink;
     this.OperationContext = operationContext;
 }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:14,代碼來源:DataServiceODataWriterNavigationLinkArgs.cs

示例6: WritingNavigationLinkArgs

 /// <summary>
 /// Initializes a new instance of the <see cref="WritingNavigationLinkArgs"/> class.
 /// </summary>
 /// <param name="link">The link.</param>
 /// <param name="source">The source.</param>
 /// <param name="target">The target.</param>
 public WritingNavigationLinkArgs(ODataNavigationLink link, object source, object target)
 {
     Util.CheckArgumentNull(link, "link");
     Util.CheckArgumentNull(source, "source");
     Util.CheckArgumentNull(target, "target");
     this.Link = link;
     this.Source = source;
     this.Target = target;
 }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:15,代碼來源:WritingNavigationLinkArgs.cs

示例7: VisitNavigationLink

            protected override void  VisitNavigationLink(ODataNavigationLink navigationLink)
            {
                bool? expectedIsCollectionValue;
                if (this.expectedIsCollectionValues != null && this.expectedIsCollectionValues.TryGetValue(navigationLink.Name, out expectedIsCollectionValue))
                {
                    this.assertionHandler.AreEqual(
                        expectedIsCollectionValue,
                        navigationLink.IsCollection,
                        "Value for IsCollection on NavigationLink '{0}' is unexpected",
                        navigationLink.Name);
                }

                base.VisitNavigationLink(navigationLink);
            }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:14,代碼來源:NavigationLinkIsCollectionPropertyValidator.cs

示例8: ValidateShortIntegrationFeedReading

        public void ValidateShortIntegrationFeedReading()
        {
            var initialFeed = new ODataFeed() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products")};
            
            var productItem = new ODataEntry() {Id = new Uri("http://services.odata.org/OData/OData.svc/Products(0)")};
            productItem.Properties = new ODataProperty[] {new ODataProperty() {Name = "Id", Value = 0}};

            var categoryNavigationLink = new ODataNavigationLink() {Name = "Category"};

            var categoryItem = new ODataEntry() { Id = new Uri("http://services.odata.org/OData/OData.svc/Categories(0)") };
            categoryItem.Properties = new ODataProperty[] { new ODataProperty() { Name = "Id", Value = 0 } };

            var productsNavigationLink = new ODataNavigationLink() { Name = "Products" };

            var supplierNavigationLink = new ODataNavigationLink() { Name = "Supplier" };

            var testODataReader = new TestODataReader()
            {
               new TestODataReaderItem(ODataReaderState.FeedStart, initialFeed),
               new TestODataReaderItem(ODataReaderState.EntryStart, productItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, categoryNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryStart, categoryItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, productsNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, productsNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryEnd, categoryItem),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, categoryNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkStart, supplierNavigationLink),
               new TestODataReaderItem(ODataReaderState.NavigationLinkEnd, supplierNavigationLink),
               new TestODataReaderItem(ODataReaderState.EntryEnd, productItem),
               new TestODataReaderItem(ODataReaderState.FeedEnd, initialFeed),
            };

            ClientEdmModel clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);

            var responsePipeline = new DataServiceClientResponsePipelineConfiguration(new DataServiceContext());
            var odataReaderWrapper = ODataReaderWrapper.CreateForTest(testODataReader, responsePipeline);
            FeedAndEntryMaterializerAdapter reader = new FeedAndEntryMaterializerAdapter(ODataFormat.Atom, odataReaderWrapper, clientEdmModel, MergeOption.OverwriteChanges);

            int readCounter = 0;

            while (reader.Read())
            {
                readCounter++;
            }

            readCounter.Should().Be(2);
        }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:47,代碼來源:FeedAndEntryMaterializerAdapterUnitTests.cs

示例9: PropertySettersNullTest

        public void PropertySettersNullTest()
        {
            ODataNavigationLink navigationLink = new ODataNavigationLink()
                {
                    Name = "NewLink",
                    Url = new Uri("http://odata.org"),
                    IsCollection = true,
                };

            navigationLink.Name = null;
            navigationLink.Url = null;
            navigationLink.IsCollection = null;

            this.Assert.IsNull(navigationLink.Name, "Expected null value for property 'Name'.");
            this.Assert.IsNull(navigationLink.Url, "Expected null value for property 'Url'.");
            this.Assert.IsNull(navigationLink.Url, "Expected null value for property 'IsCollection'.");
        }
開發者ID:AlineGuan,項目名稱:odata.net,代碼行數:17,代碼來源:ODataNavigationLinkTests.cs

示例10: PropertyGettersAndSettersTest

        public void PropertyGettersAndSettersTest()
        {
            string name = "ODataNavigationLink";
            Uri url = new Uri("http://odatatest.org/");
            bool isCollection = true;

            ODataNavigationLink navigationLink = new ODataNavigationLink()
            {
                Name = name,
                Url = url,
                IsCollection = isCollection,
            };

            this.Assert.AreEqual(name, navigationLink.Name, "Expected equal name values.");
            this.Assert.AreSame(url, navigationLink.Url, "Expected reference equal values for property 'Url'.");
            this.Assert.AreEqual(isCollection, navigationLink.IsCollection, "Expected equal values for property 'IsCollection'");
        }
開發者ID:AlineGuan,項目名稱:odata.net,代碼行數:17,代碼來源:ODataNavigationLinkTests.cs

示例11: CheckForDuplicateNavigationLinkNameAndSetAssociationLink

        /// <summary>Checks for duplicate navigation links and if there already is an association link with the same name
        /// sets the association link URL on the navigation link.</summary>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker for the current scope.</param>
        /// <param name="navigationLink">The navigation link to be checked.</param>
        /// <param name="isExpanded">true if the link is expanded, false otherwise.</param>
        /// <param name="isCollection">true if the navigation link is a collection, false if it's a singleton or null if we don't know.</param>
        internal static void CheckForDuplicateNavigationLinkNameAndSetAssociationLink(
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            ODataNavigationLink navigationLink,
            bool isExpanded,
            bool? isCollection)
        {
            Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");
            Debug.Assert(navigationLink != null, "navigationLink != null");
            
            Uri associationLinkUrl = duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(navigationLink, isExpanded, isCollection);

            // We must not set the AssociationLinkUrl to null since that would disable templating on it, but we want templating to work if the association link was not in the payload.
            if (associationLinkUrl != null && navigationLink.AssociationLinkUrl == null)
            {
                navigationLink.AssociationLinkUrl = associationLinkUrl;
            }
        }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:23,代碼來源:ReaderUtils.cs

示例12: ValidatePropertyMatch

        /// <summary>
        /// Validates the specified <paramref name="property"/> matches 
        /// the parsed <paramref name="link"/>.
        /// </summary>
        /// <param name="property">Property as understood by the type system.</param>
        /// <param name="link">Property as parsed.</param>
        /// <param name="model">Client Model.</param>
        /// <param name="performEntityCheck">whether to do the entity check or not.</param>
        /// <returns>The type</returns>
        internal static Type ValidatePropertyMatch(ClientPropertyAnnotation property, ODataNavigationLink link, ClientEdmModel model, bool performEntityCheck)
        {
            Debug.Assert(property != null, "property != null");
            Debug.Assert(link != null, "link != null");

            Type propertyType = null;
            if (link.IsCollection.HasValue)
            {
                if (link.IsCollection.Value)
                {
                    // We need to fail if the payload states that the property is a navigation collection property
                    // and in the client, the property is not a collection property.
                    if (!property.IsEntityCollection)
                    {
                        throw DSClient.Error.InvalidOperation(DSClient.Strings.Deserialize_MismatchAtomLinkFeedPropertyNotCollection(property.PropertyName));
                    }

                    propertyType = property.EntityCollectionItemType;
                }
                else
                {
                    if (property.IsEntityCollection)
                    {
                        throw DSClient.Error.InvalidOperation(DSClient.Strings.Deserialize_MismatchAtomLinkEntryPropertyIsCollection(property.PropertyName));
                    }

                    propertyType = property.PropertyType;
                }
            }

            // If the server type and the client type does not match, we need to throw.
            // This is a breaking change from V1/V2 where we allowed materialization of entities into non-entities and vice versa
            if (propertyType != null && performEntityCheck)
            {
                if (!ClientTypeUtil.TypeIsEntity(propertyType, model))
                {
                    throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidNonEntityType(propertyType.ToString()));
                }
            }

            return propertyType;
        }
開發者ID:AlineGuan,項目名稱:odata.net,代碼行數:51,代碼來源:EntryValueMaterializationPolicy.cs

示例13: WriteNavigationLinks

        private static void WriteNavigationLinks(ODataWriter writer, object element, Uri parentEntryUri, IEdmEntityType parentEntityType, IEdmModel model, ODataVersion targetVersion, IEnumerable<string> expandedNavigationProperties) 
        {
            foreach (var navigationProperty in parentEntityType.NavigationProperties())
            {
                IEdmTypeReference propertyTypeReference = navigationProperty.Type;
                bool isCollection = navigationProperty.Type.IsCollection();

                var navigationLink = new ODataNavigationLink
                                         {
                                             Url = new Uri(parentEntryUri, navigationProperty.Name),
                                             IsCollection = isCollection,
                                             Name = navigationProperty.Name,
                                         };

                writer.WriteStart(navigationLink);

                if (expandedNavigationProperties.Contains(navigationProperty.Name))
                {
                    var propertyValue = DataContext.GetPropertyValue(element, navigationProperty.Name);

                    if (propertyValue != null)
                    {
                        var propertyEntityType = propertyTypeReference.Definition as IEdmEntityType;
                        IEdmEntitySet targetEntitySet = model.EntityContainer.EntitySets().Single(s => s.EntityType() == propertyEntityType);

                        if (isCollection)
                        {
                            WriteFeed(writer, propertyValue as IEnumerable, targetEntitySet, model, targetVersion, Enumerable.Empty<string>());
                        }
                        else
                        {
                            WriteEntry(writer, propertyValue, targetEntitySet, model, targetVersion, Enumerable.Empty<string>());
                        }
                    }
                }

                writer.WriteEnd();
            }
            
        }
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:40,代碼來源:ResponseWriter.cs

示例14: WriteStartAsync

 /// <summary>
 /// Asynchronously start writing a navigation link.
 /// </summary>
 /// <param name="navigationLink">The navigation link to write.</param>
 /// <returns>A task instance that represents the asynchronous write operation.</returns>
 public abstract Task WriteStartAsync(ODataNavigationLink navigationLink);
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:6,代碼來源:ODataDeltaWriter.cs

示例15: WriteStart

 /// <summary>
 /// Start writing a navigation link.
 /// </summary>
 /// <param name="navigationLink">The navigation link to write.</param>
 public abstract void WriteStart(ODataNavigationLink navigationLink);
開發者ID:larsenjo,項目名稱:odata.net,代碼行數:5,代碼來源:ODataDeltaWriter.cs


注:本文中的Microsoft.OData.Core.ODataNavigationLink類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。