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


C# DataServiceContext.GetMetadataUri方法代码示例

本文整理汇总了C#中DataServiceContext.GetMetadataUri方法的典型用法代码示例。如果您正苦于以下问题:C# DataServiceContext.GetMetadataUri方法的具体用法?C# DataServiceContext.GetMetadataUri怎么用?C# DataServiceContext.GetMetadataUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataServiceContext的用法示例。


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

示例1: EdmDataModelProvider

        public EdmDataModelProvider(Uri serviceUri, bool isReadonly, bool supportPagingAndSorting)
        {
            var context = new DataServiceContext(serviceUri);
            Uri metadataUri = context.GetMetadataUri();
            var doc = XDocument.Load(metadataUri.AbsoluteUri);

            var itemCollection = new EdmItemCollection(GetSchemas(doc).Select(s => s.CreateReader()));

            RelationshipEndLookup = new Dictionary<long, EdmColumnProvider>();
            TableEndLookup = new Dictionary<EntityType, EdmTableProvider>();

            var tables = new List<TableProvider>();

            // Create a dictionary from entity type to entity set. The entity type should be at the root of any inheritance chain.
            IDictionary<EntityType, EntitySet> entitySetLookup = itemCollection.GetItems<EntityContainer>().SelectMany(c => c.BaseEntitySets.OfType<EntitySet>()).ToDictionary(e => e.ElementType);

            // Create a lookup from parent entity to entity
            ILookup<EntityType, EntityType> derivedTypesLookup = itemCollection.GetItems<EntityType>().ToLookup(e => (EntityType)e.BaseType);

            _complexTypes = itemCollection.GetItems<ComplexType>();

            // Keeps track of the current entity set being processed
            EntitySet currentEntitySet = null;

            // Do a DFS to get the inheritance hierarchy in order
            // i.e. Consider the hierarchy
            // null -> Person
            // Person -> Employee, Contact
            // Employee -> SalesPerson, Programmer
            // We'll walk the children in a depth first order -> Person, Employee, SalesPerson, Programmer, Contact.
            var objectStack = new Stack<EntityType>();
            // Start will null (the root of the hierarchy)
            objectStack.Push(null);
            while (objectStack.Any()) {
                EntityType entityType = objectStack.Pop();
                if (entityType != null) {
                    // Update the entity set when we are at another root type (a type without a base type).
                    if (entityType.BaseType == null) {
                        currentEntitySet = entitySetLookup[entityType];
                    }

                    var table = CreateTableProvider(currentEntitySet, entityType, isReadonly, supportPagingAndSorting);
                    tables.Add(table);
                }

                foreach (EntityType derivedEntityType in derivedTypesLookup[entityType]) {
                    // Push the derived entity types on the stack
                    objectStack.Push(derivedEntityType);
                }
            }

            _tables = tables.AsReadOnly();

            GenerateClrTypes(serviceUri);
        }
开发者ID:davidebbo-test,项目名称:DynamicDataWCFDataService,代码行数:55,代码来源:EdmDataModelProvider.cs

示例2: CanConnectAndDownloadMetadata

        public void CanConnectAndDownloadMetadata()
        {
            var context = new DataServiceContext(new Uri("http://localhost:9000/entity"), ODataProtocolVersion.V4);
            string metadataString;
            IEdmModel model;

            using ( var http = new WebClient() )
            {
                metadataString = http.DownloadString(context.GetMetadataUri());
            }

            using ( var xmlReader = XmlReader.Create(new StringReader(metadataString)) )
            {
                model = EdmxReader.Parse(xmlReader);
            }

            var entityTypes = model.SchemaElements.OfType<IEdmEntityType>().ToArray();

            foreach ( var type in entityTypes )
            {
                Console.WriteLine("{0}{{{1}}}", type.Name, string.Join(",", type.Properties().Select(p => p.Name).ToArray()));
            }
        }
开发者ID:votrongdao,项目名称:NWheels,代码行数:23,代码来源:CommonUseCaseTests.cs

示例3: GetContainerName

        /// <summary> Get main schema container name for given service uri </summary>
        /// <param name="cxInfo">connection info</param>
        /// <returns>Container name</returns>
        static string GetContainerName(IConnectionInfo cxInfo)
        {
            // odata v4 client inherites from DataServiceContext, use it for get IEdmModel

            IEdmModel model;

            var context = new DataServiceContext(new Uri(cxInfo.DatabaseInfo.Server))
            {
                Credentials = GetCredentials(cxInfo)
            };

            var metadataUri = context.GetMetadataUri();
            using (var reader = XmlReader.Create(metadataUri.ToString()))
            {
                model = EdmxReader.Parse(reader);
            }

            var root = model.SchemaElements.OfType<IEdmEntityContainer>().Single();

            // FIX ?
            var containerName = model.DeclaredNamespaces.Count() > 1 ? root.FullName() : root.Name;

            return containerName;
        }
开发者ID:michaelaltmann,项目名称:LINQPadOData4,代码行数:27,代码来源:OData4DynamicDriver.cs

示例4: ResolveModelFromMetadataUri

 private static IEdmModel ResolveModelFromMetadataUri(DataServiceContext context)
 {
     var metadataUri = context.GetMetadataUri().AbsoluteUri;
     return EdmxReader.Parse(XmlReader.Create(metadataUri));
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:5,代码来源:JsonLightTestUtil.cs


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