question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Equivalent to ObjectContext.CreateDatabaseScript

See original GitHub issue

This 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:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Oct 11, 2017

I will try to get this added to EF Core Power Tools https://github.com/ErikEJ/SqlCeToolbox/issues/521

0reactions
bricelamcommented, Oct 18, 2017

I suppose I was thinking the GenerateScript method, but it doesn’t look like much can be reused there.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found