Entity Framework 4.1. First code stop

I am having problems working with EF 4.1 on my computer. There seems to be some problems with my database settings. I tried this simple walkthrough: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

But when he reaches db.Categories.Add (food); he just freezes.

I have regular SQL Server 2008 R2 installed, not SQL Express. There are also problems creating .mdf files instead of connecting directly to the local SQL server.

I also tried adding an entity model with a database connection, but this does not seem to work. Does anyone have pointers to me.

Thanks for any answers :)

edit: Now I get a System.Data.ProviderIncompatibleException with "The provider does not return the ProviderMaifestToken string"

+1
c # entity-framework database-connection ef-code-first
source share
3 answers

I found a problem. These tutorials do not contain information about some of the vital settings that I need to get to work.

1) Your application should have App.config containing a connection string with a name with the same name as your class inherited from DbContext. In my case, "TestEF_CF.ProductContext".

2) The database cannot be created before you start using it. Just set the start directory to the name you want to create the Entity Framework when it automatically creates the database.

As soon as I did this, it worked correctly. I got one more step, but got an exception when I tried to save the database. When EF automatically created the database, everything worked fine.

One thing that may have made it more problematic for my development environment may be that I cannot directly use local mdf files. However, this does not hurt if the EF team can share these details more openly than now, it will save me (or us) from disappointment.

+1
source share

I assume this is due to reinitializing the database. If your EF code tries to delete and create a database with SQL Management Studio, open or connect. This situation arises.

+1
source share

Try installing the data source in the connection string. \ SQLEXPRESS

It worked for me

0
source share

All Articles