ReverseEngineeringGenerator in Entity Framework Core 2.1

c# entity-framework entity-framework-core reverse-engineering scaffolding

Question

Based on this article by Mr Rowan Miller I want to use EF Core scaffolding system by code.

// Add base services for scaffolding
var serviceCollection = new ServiceCollection()
    .AddScaffolding()
    .AddLogging();

// Add database provider services
var provider = new SqlServerDesignTimeServices();
provider.ConfigureDesignTimeServices(serviceCollection);

var serviceProvider = serviceCollection.BuildServiceProvider();

var generator = serviceProvider.GetService<ReverseEngineeringGenerator>();
var options = new ReverseEngineeringConfiguration
{
    ConnectionString = @"Server=(localdb)\mssqllocaldb;Database=Northwind;Integrated Security=true",
    ProjectPath = @"C:\temp\",
    ProjectRootNamespace = "My.Namespace"
};

generator.GenerateAsync(options).Wait();

But it does not work with latest EF Core 2.1.

Can anyone help me to update the code? (an updated article)

1
0
4/19/2018 5:03:38 AM

Accepted Answer

Code for 2.1 is available here: https://github.com/ErikEJ/SqlCeToolbox/blob/master/src/GUI/ReverseEngineer20/EFCoreReverseEngineer.cs

var scaffolder = serviceProvider.GetService<IReverseEngineerScaffolder>();
var scaffoldedModel = scaffolder.ScaffoldModel(...
var filePaths = scaffolder.Save(scaffoldedModel,...
1
4/19/2018 4:41:16 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow