2

I'm using EF 6.0.0 and .Net 4.5.

I face a very confusing problem. Me and one of my colleagues are working on the domain model section of our project on two different clients. The problem is:

1- Me and my colleagues start with the absolutely identical project and we are completely synced with the source control.

2- When I change the model for example add a property then Add-Migration FromA then Update-Database it works great. The generated code file contains just one command that is to add the column.

3- Meanwhile, after the db is updated and just before I check in something to source control, my colleague adds another property and then Add-Migration FromA then Update-Database. And guess what? This generated code file has a command to drop the column I newly added!!!

I added another column using native Sql, and fortunately the column is not going to be deleted.

I deleted the __MigrationHistory table and the remove column didn't get generated.

I turned off initializer Database.SetInitializer<MyContext>(null), no success.

So, my guess is that EF Migrations compares current model with the last one stored in __MigrationHistory table not the last local snapshot stored in .resx file. Am I right? Any way to solve the problem?

jennyfofenny
  • 4,359
  • 2
  • 17
  • 15
Hans
  • 2,674
  • 4
  • 25
  • 48
  • 1
    check this out. https://msdn.microsoft.com/en-us/data/dn481501.aspx – Hamid Pourjam Jun 13 '15 at 19:48
  • @dotctor This is completely different. The difference is that I don't check in anything. The only changes visible to other clients are in DB not source control – Hans Jun 13 '15 at 20:02
  • are you sharing a single instance of database? – Hamid Pourjam Jun 13 '15 at 20:03
  • 2
    you shouldn't, It's like you both edit a same source file at a same time. use local instances of db and do not share them and do the merging process described in that article when merging conflicts happen – Hamid Pourjam Jun 13 '15 at 20:08
  • 2
    Look at this one: http://stackoverflow.com/q/13314725/861716 – Gert Arnold Jun 13 '15 at 20:14
  • @dotctor thanks a lot. I missed the point that every developer should work on local db to compare himself to his own previous works. – Hans Jun 13 '15 at 20:20
  • @dotctor But why does EF even take __MigrationHistory table into account? I expected it compares current model with the last snapshot stored in resource file. If it had done the job like this, this problem wouldn't have occurred. If current model is always get compared with __MigrationHistory what is the point of snapshot? – Hans Jun 13 '15 at 20:28
  • I don't know, that is the EF team design decision. – Hamid Pourjam Jun 13 '15 at 20:31
  • Yep, if you read that whole msdn article like it says you should, you'll walk away with the wrong impression. The migrations that get generated definitely depend (also) upon what's in the database - not just what's in the previous resx file. – mwardm Jul 07 '15 at 13:37

0 Answers0