0

I am trying to add code first,but the App_Data folder is empty.

Web.config

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Movie-20170604111514.mdf;Initial Catalog=aspnet-Movie-20170604111514;Integrated Security=True"
          providerName="System.Data.SqlClient" />
    <add name="MovieDBContext" connectionString="Data Source=(localDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
          providerName="System.Data.SqlClient" /> 
</connectionStrings>

Model

public class MovieDBContext : DbContext
{
    public DbSet<Movie> Movies { get; set; }    
}

Can anyone help me ? Thanks in advance.

Arman
  • 45
  • 7
  • This might not be important but you're using `Movies.pdf` instead of `Movies.mdf` – dcg Jun 07 '17 at 11:56
  • Thanks @dcg ,i already correct that,but it does not solve the problem. – Arman Jun 07 '17 at 11:59
  • You nee to check this ans : https://stackoverflow.com/questions/44070400/how-to-implement-a-data-access-layer-within-mvc-controller/44070806#44070806 – Laxman Gite Jun 07 '17 at 12:14

1 Answers1

1

You need to add a constructor in your MovieDBContext class as following:

public class MovieDBContext : DbContext
{
    public MovieDBContext () : base("Name=MovieDBContext")
    {
    }

    public DbSet<Movie> Movies { get; set; }    
}

For more detail you can read following link: http://www.entityframeworktutorial.net/code-first/entity-framework-code-first.aspx

Harsh Sharma
  • 910
  • 1
  • 7
  • 20