A
A
Alexsbr2017-10-03 17:02:45
C++ / C#
Alexsbr, 2017-10-03 17:02:45

How to run Entity Framework migrations from code?

Hello! if anyone knows, please help.
Do you need to create a database every time before a unit test on a SQL SERVER instance and roll all existing migrations? and then delete the database after the test
. I know that you can run migrations from the console, but I need to do this from the unit test class.
I would be grateful if anyone could suggest how to do this.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MrDywar Pichugin, 2017-10-03
@Dywar

https://programmingwithmosh.com/become-a-full-stac...
Part 3: Become a Full-stack .NET Developer – Architecture and Testing
In this course, he teaches and shows how to test MVC, API + EF + Repository.
Integration and unit tests.

D
Dmitry Kovalsky, 2017-10-04
@dmitryKovalskiy

The question sounds very strange. Before each unit test, you do not need to roll up the database server. Only before integration and unit tests of the data access layer.
What is the problem? If you don’t know where to write, there are method attributes like SetUp and TearDown in NUnit that allow you to write any logic for creating an environment for running tests within the current test class.
If you do not know what to write - well, you can try to call the same PowerShell console commands. Or more direct instructions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question