Question

I am using a T4 template that generates POCOs from EDMX files.

All underlying entities have their own schemas. That answer describes how you can extract the schema name from an EDMX:

StoreItemCollection sic;
loader.TryCreateStoreItemCollection(inputFile, out sic);
EntityContainer sicEntityContainer = sic.GetItems<EntityContainer>().First();

EntitySet eset = sicEntityContainer.GetEntitySetByName(code.Escape(entity), true);
string schemaName = eset.MetadataProperties["Schema"].Value.ToString();

If I look at the content of an EDMX file, I find out that there is a Schema attribute for each entity:

<EntitySet Name="Table_1"
           EntityType="TestModel.Store.Table_1"
           store:Type="Tables"
           Schema="Blubb" />

At this point anything works fine and I can extract the schema name.

AND HERE IS THE PROBLEM:

Since one or two month Visual Studio 2010 adds a prefix called store to the Schema attribute of newer Entities in my model.

<EntitySet Name="Table_1"
           EntityType="TestModel.Store.Table_1"
           store:Type="Tables"
           store:Schema="Blubb" />

So I cannot extract the schema by using the logic of the upper linked article.

I have to remove these prefixes with a text editor manually, so anything can be worked fine.

My questions:

  1. What is the reason for that?
  2. How can I read-out attributes with namespaces like store:Schema?
Was it helpful?

Solution

You need to prefix the "Type/Schema" with its namespace

ie:

 eset.MetadataProperties["http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Type"].Value.ToString(); 
 eset.MetadataProperties["http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator:Schema"].Value.ToString(); 

OTHER TIPS

Not sure if this will help but it might, See http://brewdawg.github.io/Tiraggo.Edmx/ and you can install it from NuGet. It serves up ALL of the metadata in your edmx files, including all the mappings, low level SQL data types per column, all that kind of stuff, look at the sample on the page and you'll see how easy it is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top