Entity Framework Code First Apporach

In this we create the model first and its entities. after make all our model, view and controller, “Code First” approach can auto generate the database for us.

1. EF’s “code first development” support is currently enabled with a separate download that runs on top of the core EF built-into .NET 4.  CTP4 of this “code-first” library shipped this week and can be downloaded here

2. We can create the database one of two ways:

  1. Manually create and define the schema ourselves using a database tool (e.g. SQL Management Studio or Visual Studio)
  2. Automatically create and generate the schema directly from our model classes using the EF Code-First library

This second option is pretty cool and is what we are going to use for our NerdDinner application.

Configuring our Database Connection String

To begin with, we’ll setup a connection-string to point to where we want our database to live.  We’ll do this by adding a “NerdDinners” connection-string entry to our application’s web.config file like so:

image 

To auto-generate the database from model we need to use providerName="System.Data.SqlServerCe.4.0" in connection string as above.
Share the joy
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.