How do I make EF-CodeFirst ignore the creation of existing views?

I have it View

in my existing database which is completely built by EF-CodeFirst . Now I added View

Entity

, but when I run my application, it throws Exception is There is already an object named 'View' in the database

. How to solve this problem?

+3


source to share


1 answer


Explanation of what is happening:
You are getting this error because there is already an object (view or table, etc.) in the database called "View" and EF-Code First with migrations is trying to re-create it.

When you start your application, EF Code First looks in the database for the dbo .__ MigrationHistory table (usually found in the system tables). This table keeps track of which migrations have been run. Take a look in this table to see if migrations create it and populate it correctly.



Answer for you:
Make sure you are using migration and EF code correctly. If you can, try deleting the existing View (or table) and letting EF create it again. At this point, if you have your migrations properly configured, your migration table should "update" itself with the migration and have this entry in the MigrationHistory table.

+1


source







All Articles