IT:AD:Code First:Deployment
Deployment
Warning: Code first has no change tracking story. The process to follow is:
* Read this – might be useful: http://weblogs.asp.net/jgalloway/archive/2011/02/24/generating-ef-code-first-model-classes-from-an-existing-database.aspx
- For the future:
- See 'Code First Migrations' (http://bit.ly/s9ASt2)
Db Initialization
Excellent in depth analysis of the steps happening under the covers: * http://blog.oneunicorn.com/2011/04/15/code-first-inside-dbcontext-initialization/
Saving SQL Script and EDMX
Astoundingly, one can build everything via CodeFirst – and then dump it to a SQL script to be optimized as needed:
using (var context = new Context()) { string script = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript(); }
And holy catnip, one can get the edmnx as well:
using (var context = new Context()) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create(@"Model.edmx", settings)) { EdmxWriter.WriteEdmx(context, writer); } }