I am trying to process the metadata information for an Entity Framew开发者_JS百科ork data model by using the MetadataWorkspace. I know how to extract all tables, but the following code will return me all views and all tables from the storage model.
using ( NorthwindEntities dbContext = new NorthwindEntities() )
{
MetadataWorkspace workspace = dbContext.MetadataWorkspace;
string temp = ( dbContext.Categories as ObjectQuery ).ToTraceString();
IEnumerable<EntityType> tables = workspace.GetItems<EntityType>( DataSpace.SSpace );
}
When I take a look at the edmx file, I can see that there is an attribute named store:Type that describes which EntitySet is a table and which is a View. Such property is not esposed by the EntityType object:
<EntitySet Name="Invoices" EntityType="NorthwindModel.Store.Invoices" store:Type="Views">
So my question is: Is there a way to recognize which EntitySet is a table and which is a View by using only the MetadataWorkspace (I mean without processing the XML ;))
Thanks in advance
After digging deeper in the EF MetadataWorkspace I believe I found a solution:
using ( AdventureWorksEntities dbContext = new AdventureWorksEntities() )
{
MetadataWorkspace mw = dbContext.MetadataWorkspace;
dbContext.Locations.ToTraceString();
EntityContainer entityContainer = mw.GetItems<EntityContainer>( DataSpace.SSpace ).Single();
EntitySet entitySet = entityContainer.GetEntitySetByName( "Location", true );
string type = entitySet.MetadataProperties[ "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Type" ].Value.ToString();
}
If I should be honest it is really difficult to work with the Entity Framework metadata. At least they should do strongly-typed properties.
精彩评论