I'm trying to use 2 contexts on the same database.
To create the database I'm using DbContext.Database.EnsureCreated()
The first EnsureCreated call works fine, the second EnsureCreated call does not work.
Some considerations
Profiling SQL Server I can see that EF Core checks for the existence of a table
IF EXISTS (
SELECT
*
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_TYPE = 'BASE TABLE')
SELECT 1
ELSE
SELECT 0
then it runs the create table statement.
If there is a user table on the DB nothing is done...
Is there a way to force table creations from entities scaffolding?
Actually I found only this way.
RelationalDatabaseCreator databaseCreator =
(RelationalDatabaseCreator) context.Database.GetService<IDatabaseCreator>();
databaseCreator.CreateTables();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With