本文整理汇总了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);
}
示例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()));
}
}
示例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;
}
示例4: ResolveModelFromMetadataUri
private static IEdmModel ResolveModelFromMetadataUri(DataServiceContext context)
{
var metadataUri = context.GetMetadataUri().AbsoluteUri;
return EdmxReader.Parse(XmlReader.Create(metadataUri));
}