Answered by:
Why EF is not able to drop and create my database in the unit test

Question
-
hi,
As referred in this issue ( Old Post ), I copy the solution for an other unit test, but an other problem appears. I precise that I am not in Code First model.
Here is my issue:
Do you have any idea ? Why the first class works, and not this one ?
Regards,
Arnaud H.
- Edited by arnaud.helin Sunday, August 21, 2016 11:57 PM
Sunday, August 21, 2016 11:55 PM
Answers
-
Hi arnaud.helin,
We know that the
DropCreateDatabaseIfModelChanges
initializer drops and recreates the database if the database schema no longer matches the classes in your code. It determines "if model changes" by looking at your classes and by looking at a table called_MigrationHistory
in the database. If there is no such table, it throws the exception which you providing.There are two workarounds could resolve the issue for your reference.
1. Use a different initializer (such as
DropCreateDatabaseAlways
) or2. Make sure that there is a
_MigrationHistory
table in your database, by enabling Entity Framework code first migrations.Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Zhanglong WuMicrosoft contingent staff Monday, August 22, 2016 5:25 AM
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Tuesday, August 30, 2016 9:56 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, August 31, 2016 4:49 AM
Monday, August 22, 2016 5:24 AM -
Hi arnaud.helin,
>>Do you have any idea about howI can easily create a new independantDatabase with my actual Database ? (a sort of migration)
I would suggest that you could create the database by using entity framework migrations.For more information, please refer to:
Best regards,ColeWu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Zhanglong WuMicrosoft contingent staff Tuesday, August 30, 2016 9:55 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, August 31, 2016 4:49 AM
Thursday, August 25, 2016 8:17 AM
All replies
-
Do you have any idea ?
It's not a unit test you are doing. Is it worth the aggravation of an integration test you are trying to do?
Monday, August 22, 2016 12:57 AM -
Hi arnaud.helin,
We know that the
DropCreateDatabaseIfModelChanges
initializer drops and recreates the database if the database schema no longer matches the classes in your code. It determines "if model changes" by looking at your classes and by looking at a table called_MigrationHistory
in the database. If there is no such table, it throws the exception which you providing.There are two workarounds could resolve the issue for your reference.
1. Use a different initializer (such as
DropCreateDatabaseAlways
) or2. Make sure that there is a
_MigrationHistory
table in your database, by enabling Entity Framework code first migrations.Best regards,
Cole Wu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Zhanglong WuMicrosoft contingent staff Monday, August 22, 2016 5:25 AM
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Tuesday, August 30, 2016 9:56 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, August 31, 2016 4:49 AM
Monday, August 22, 2016 5:24 AM -
Hi DA924x,
I know that i shouldn't call it unittest but it is because i have these problems when i test my EF syntax.
But you are right it is not a "real" unit test.
Monday, August 22, 2016 8:32 AM -
Hi cole wu,
So you suggest me to recreate the Database manually ? The thing I want is a Database completely isolated from the code. This is the reason I did a Code First database but change it afterwards.
Steps I did are:
1) Code in C# with EF Syntax
2) Generate the Database
3) Export T-SQL Script to create and drop the Database when I want.
4) Delete the _MigrationHistory table
For sure I thought that the _MigrationHistory table was not useless but I thought it was just an history table, like a log table.
Do you have any idea about how I can easily create a new independant Database with my actual Database ? (a sort of migration)
Regards,
Arnaud H.
Monday, August 22, 2016 8:39 AM -
Hi arnaud.helin,
>>Do you have any idea about howI can easily create a new independantDatabase with my actual Database ? (a sort of migration)
I would suggest that you could create the database by using entity framework migrations.For more information, please refer to:
Best regards,ColeWu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Zhanglong WuMicrosoft contingent staff Tuesday, August 30, 2016 9:55 AM
- Marked as answer by Herro wongMicrosoft contingent staff Wednesday, August 31, 2016 4:49 AM
Thursday, August 25, 2016 8:17 AM