Entity Framework 4.1 Code First Freeze

南楼画角 提交于 2019-12-08 09:59:31

I guess this is because Database Re-Initialization. If your EF code try to drop and create database with SQL Management Studion open or connected. This situation comes up.

I found the problem. These tutorials do not contain information about some vital adjustments that I needed to make it work.

1) Your application must have an App.config containing a connectionstring named with the same name as your class that inherited from DbContext. In my case "TestEF_CF.ProductContext".

2) The database cannot be created before you start to use it. Just set the Initial Catalogue to the name you want Entity Framework to create when it autocreate the database.

Once I did this, it worked properly. I got further with the first step, but got an exception when I tried to save to the database. When EF autocreated the database everything worked fine.

One thing that may have made it more problematic on my development environment could be the fact that I cannot use local mdf files directly. Still it would not hurt if the EF team could share these details more open than they do now, it would save me (or us) some frustration.

Try setting the datasource on the connection string to .\SQLEXPRESS

It did work for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!