Reputation: 5104
I've been using EF for a while now, always in the Model-First approach. Now I'm adventuring through Code-First lands. The thing is: I've been having issues with automatic table creation.
According to some sites it is possible. And I've tried their approach with no success.
Here's one of the things I've tried: Database.CreateIfNotExists()
No luck...
My connection string is perfect and working. If I add the table manually it does work. The problem is when I don't have the table created. It just doesn't create as I was said it would.
My classes are correctly decorated. (Again: It's working when I have the DBs created)
Any suggestions? Does this feature really works?
I'm using:
Visual Studio 2010 Professional
EntityFramework 4.3.1 (although I tried with 4.1 also)
SQL Server 2008 R2
Thanks in advance.
Upvotes: 6
Views: 13571
Reputation: 3213
There are three database initializers that are included with entity framework they all implement IDatabaseInitializer<Context>
interface. They are:
As you see the default API does not have the initializer that just creates tables, instead it does the whole database. However there are other initializers that people have created, there is one that does exact same thing that you want.
It's in the Nuget package EFCodeFirst.CreateTablesOnly
Another option is to create your own initializer if that's something you really need.
Upvotes: 8