Imports System
Imports System.Collections.ObjectModel
Imports System.Data
Imports System.Data.EntityClient
Imports System.Data.Metadata.Edm
Class BrowseTypes
Public Shared Sub Main()
Try
' Establish a connection to the underlying data provider by
' using the connection string specified in the config file.
Using connection As EntityConnection = _
New EntityConnection("Name=AdventureWorksEntities")
' Open the conection.
connection.Open()
' Access the metadata workspace.
Dim workspace As MetadataWorkspace = _
connection.GetMetadataWorkspace
' Browse the metadata type hierarchy in the conceptual model.
BrowseTypesExample(workspace, DataSpace.CSpace)
' Browse the metadata type hierarchy in the storage model.
BrowseTypesExample(workspace, DataSpace.SSpace)
End Using
Catch exceptionMetadata As MetadataException
Console.WriteLine("MetadataException: {0}", _
exceptionMetadata.Message)
Catch exceptionMapping As MappingException
Console.WriteLine("MappingException: {0}", _
exceptionMapping.Message)
End Try
End Sub
Public Shared Sub BrowseTypesExample( _
ByVal workspace As MetadataWorkspace, _
ByVal model As DataSpace)
' Get a collection of the GlobalItems.
' An GlobalItem class is the base class for
' the entity data model types and entity containers.
Dim items As ReadOnlyCollection(Of GlobalItem) = _
workspace.GetItems(Of GlobalItem)(model)
' Iterate through the collection to get each item.
Dim item As GlobalItem
For Each item In items
Dim entityContainer As EntityContainer = _
TryCast(item, EntityContainer)
If (Not entityContainer Is Nothing) Then
Console.WriteLine("EntityContainer Name: {0}", _
entityContainer.Name)
Continue For
End If
Dim entityType As EntityType = TryCast(item, EntityType)
If (Not entityType Is Nothing) Then
Console.WriteLine("EntityType Name: {0}, Namespace: {1}", _
entityType.Name, entityType.NamespaceName)
Continue For
End If
Dim associationType As AssociationType = _
TryCast(item, AssociationType)
If (Not associationType Is Nothing) Then
Console.WriteLine("AssociationType Name: {0}, Namespace: {1}", _
associationType.Name, associationType.NamespaceName)
Continue For
End If
Dim primType As PrimitiveType = TryCast(item, PrimitiveType)
If (Not primType Is Nothing) Then
Console.WriteLine("PrimitiveType Name: {0}, Namespace: {1}", _
primType.Name, primType.NamespaceName)
Continue For
End If
Dim functionEdm As EdmFunction = TryCast(item, EdmFunction)
If (Not functionEdm Is Nothing) Then
Console.WriteLine("EdmFunction Name: {0}, Namespace: {1}", _
functionEdm.Name, functionEdm.NamespaceName)
Continue For
End If
Next
End Sub
End Class