Using C# on a Win7 machine I am needing to dynamically change the schema type on an Entity Framework 6.2 edmx xml file prior to instansiating EF. I can filter the edmx Xml for the "Schema" attribute for tables but not for views. Tables use the non prefixed Attribute "Schema" and Views for some odd reason use the prefixed Attribute "store:Schema".
Unfortunately if I filter Attributes for the obvious "store:Schema" I get an XmlException saying "The ':' character, hexadecimal value 0x3A, cannot be included in a name.". I've tried various ways to filter for this needed Attribute so that I can change the Attribute to my custom schema name so that I can later have EF run a view from another schema than "dbo". My XML code is below. How can I filter the storage Descendants for a prefixed Attribute?
// How can I specify the schema prefix for an EF edmx <EntitySet> view type?
// Table <EntitySet> has a non prefixed attribute call "Schema"
// EF view <EntitySet> has a prefixed attribute called "store:Schema" that I cannot seem to filter for
// Filtering with "store:Schema" throws an XmlException
// - "The ':' character, hexadecimal value 0x3A, cannot be included in a name."
//
// Change the schema for all the tables and views from the dbo (or whatever) EF specified schema (if any)
// to the desired schema.
foreach (var entitySet in storageXml.Descendants(storageNS + "EntitySet"))
{
// this works fine for tables but views have prefixed attribute "store:Schema" so are not found
var schemaAttribute = entitySet.Attributes("Schema").FirstOrDefault();
if (schemaAttribute != null)
{
schemaAttribute.SetValue(schema);
}
// EF storage xml species a prefix on view Schema attribute as "store:Schema" so are not found
// here we try various ways to get any "store:Scehma" attributes so far unsuccessfully
// the most obvious incantaion throws an XmlException as mentioned above
schemaAttribute = entitySet.Attributes("store:Schema").FirstOrDefault();
// the next three run fine but do not filter out the needed attribute
//schemaAttribute = entitySet.Attributes(XName.Get("store", "Schema")).FirstOrDefault();
//schemaAttribute = entitySet.Attributes(XName.Get("Schema", "store")).FirstOrDefault();
//XNamespace ns = "store";
//schemaAttribute = entitySet.Attributes(ns + "Schema").FirstOrDefault();
if (schemaAttribute != null)
{
// I never hit this though can see the desired XElement w/ a "store:Schema" attribute
// I need to reset this schema // does it need to be set as store: prefixed?
schemaAttribute.SetValue(schema);
}
}