How to distinguish views from tables in EF MetadataWorkspace?

I am trying to process metadata information for an Entity Framework data model using MetadataWorkspace. I know how to retrieve 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 look at the edmx file, I see that there is an attribute called store: Type that describes which EntitySet is a table and represents a view. This property is not associated with an 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 using only metadata? (I mean without XML processing;))

Thanks in advance

+3
source share
1 answer

EF MetadataWorkspace , :

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();
}

, Entity Framework . , .

+2

Source: https://habr.com/ru/post/1779366/


All Articles