.NET Core: Retrieving instance of MigrationsSqlGenerator from DbContext

Viewed 45

With EntityFrameworkCore, is there a way to retrieve a MigrationsSqlGenerator corresponding to my current DbContext (it can be linked to a Sql Server or a postgres database).

The goal is to be able to create table dynamically by code without taking care of difference between sql syntax.

I've already try to use the CreateTable method of MigrationBuilder("Microsoft.EntityFrameworkCore.SqlServer") but I need to use a "SqlGenerator" to get the corresponding sql.

1 Answers

Finally I found it : dbContext.GetService<IMigrationsSqlGenerator>();

Related