I have a .NET core 3 project with SQL Server and I'm trying to write a test for an initialize service which will run only the first time database is created.
There is one database with a lot of dbcontexts
. What I'm trying to do is to drop the database and recreate it, then run the service on it and check if it worked properly.
What I'm doing now is calling the ensureDeleted()
and ensureCreated()
on all of the contexts in a foreach
loop and its kind of working for an empty database.
My question is:
-
Will the
ensureDeleted()
fail if there are data in the db that are dependent to each other, since each context only deletes some of the database tables? -
If so how can I prevent this? And is there a better way to do it?
-
Can I just drop the database and recreate it in .NET core? If I can is it a good choice considering now with
ensureDeleted()
I'm only deleting the tables not the whole Database
*Also I tried doing my test with sqllite and it didn't work out for me since its very different then server (it doesn't have schema).
Aucun commentaire:
Enregistrer un commentaire