Created
June 26, 2013 01:27
-
-
Save raghuramn/5864013 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEdmModel GetEdmModel(this DbContext context) | |
{ | |
using (MemoryStream stream = new MemoryStream()) | |
{ | |
using (XmlWriter writer = XmlWriter.Create(stream)) | |
{ | |
EdmxWriter.WriteEdmx(context, writer); | |
writer.Close(); | |
stream.Seek(0, SeekOrigin.Begin); | |
using (XmlReader reader = XmlReader.Create(stream)) | |
{ | |
return Microsoft.Data.Edm.Csdl.EdmxReader.Parse(reader); | |
} | |
} | |
} | |
} |
The Bad fix
public static IEdmModel GetEdmModel(this AppDbContext context)
{
using (MemoryStream stream = new MemoryStream())
{
using (XmlWriter writer = XmlWriter.Create(stream))
{
EdmxWriter.WriteEdmx(context, writer);
writer.Close();
stream.Seek(0, SeekOrigin.Begin);
var sr = new StreamReader(stream);
var myStr = sr.ReadToEnd();
myStr = myStr.Replace("App.Data", "App.Models");
using (XmlReader xmlReader = XmlReader.Create(new StringReader(myStr)))
{
return Microsoft.Data.Edm.Csdl.EdmxReader.Parse(xmlReader);
}
}
}
}
@raghuramn, Could we get a new sample of this that works with the latest bits on MyGet (EdmLib 6.4)? I arrived here via this work item.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems that the example above produces wrong namespaces.
I got the entity context in App.Data and the models in App.Models and WepApi in App.Web
The Schema renders the Models in App.Data
By convert the stream to a string and do a Replace("App.Data", "App.Models") then it works fine.
Please fix the sample above