Equivalent to ObjectContext.CreateDatabaseScript
See original GitHub issueThis is one of my favorite features of the EF Power Tools, and I think we should have similar functionality in EF Core.
My proposal is an db.Database.GenerateCreateScript()
extension method. Here’s the implementation. 😉
public static string GenerateCreateScript(this DatabaseFacade database)
{
var model = database.GetService<IModel>();
var differ = database.GetService<IMigrationsModelDiffer>();
var generator = database.GetService<IMigrationsSqlGenerator>();
var sql = database.GetService<ISqlGenerationHelper>();
var operations = differ.GetDifferences(null, model);
var commands = generator.Generate(operations, model);
var builder = new StringBuilder();
foreach (var command in commands)
{
builder
.Append(command.CommandText)
.AppendLine(sql.BatchTerminator);
}
return builder.ToString();
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:7 (7 by maintainers)
Top Results From Across the Web
ObjectContext.CreateDatabaseScript not creating indexes
Does anyone know of an alternative way of getting the indexes in place without having to manually add them back in after creating...
Read more >ObjectContext.CreateDatabaseScript Method (System.Data ...
Generates a data definition language (DDL) script that creates schema objects (tables, primary keys, foreign keys) for the metadata in the ...
Read more >ObjectContext Class (System.Data.Objects)
Constructors. Initializes a new instance of the ObjectContext class with the given connection. During construction, the metadata workspace is extracted from ...
Read more >From NHibernate to Entity Framework 6 - Part 1: the mapping ...
Entity Framework's equivalent of Nhibernate's Session is DbContext . Both NH's Session and EF's DbContext have the same purpose, are used in ...
Read more >Migrating Entity Framework 6 projects to ...
Ability to generate a DDL script for database object creation, like ObjectContext.CreateDatabaseScript() (Issue #2943); Allow Identity ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I will try to get this added to EF Core Power Tools https://github.com/ErikEJ/SqlCeToolbox/issues/521
I suppose I was thinking the GenerateScript method, but it doesn’t look like much can be reused there.