I\'m using EF 4.1 code first. Running into a very weird situation: Database does not exist, code is executed and as soon as the code wants to execute a query against the reposit
For the sake of future use: it turns out that EF 4.1 was not the source of my problems!
As i stated above (after the EDIT) it is possible to run the (UNCHANGED) code in a new project and it will execute as expected!
It is also true that i successfully created a new project, referenced the model and the DAL (repositories, etc) of the original project and the new code in the new project executed as expected.
This lead me to think that this is a Visual Studio 2010 Solution(or Project)-based problem. I cannot remember having done anything weird to this solution (the only thing i did was adding a test-project, which i afterward deleted, and also some - i think three files - related to this project test-project - IS THIS WEIRD?!).
The only solution i could think of, was to create a new Visual Studio 2010 Solution from scratch and place the original Projects in the solution tree...and it worked!
I ran into this and after digging around a bit have discovered it's a problem with Code First thinking it's the sole owner of the schema.
http://social.msdn.microsoft.com/Forums/en/adonetefx/thread/79885a6d-e0f2-4948-8f3c-d5da1941ace3
They havent quite got it figured out for user instances of the DB (that's where 'User Instance = true' is in your connection string and you create an SQL Server file in your App_Data folder). So either remove it or use the following:
Data Source=.\SQLEXPRESS;Database=NerdDinners;Integrated Security=SSPI;
Code First will create and attach (or modify) a database directly to your instance of SQL Server. You can then connect to it using Management Studio or VS Server Explorer.
thanks Savvas, for sharing the fact that creating a new solution solved your problem. I faced the same weird issue with EF 4.1, and deleting the VS2010 "SUO" file seemed to do the trick for me. Thought I'd share this to save others the time to recreate the solution from scratch.