A day with .Net

My day to day experince in .net

Create database in App_Data folder Entity Frame Work Code First.

Posted by vivekcek on May 30, 2013

If you want EF to create your database under App_Data folder.

First set your connection string as below. Please note that the name should be same as your DbContext class name.

<add name="AppDB"
           connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|mydatabase.mdf;User Instance=true;Initial Catalog=myDataBase"
           providerName="System.Data.SqlClient" />

Example of context file.

public class AppDB : DbContext
    {
        public AppDB()
            : base("name=AppDB")
        {
            
        }
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s