TheFallenOne
TheFallenOne

Reputation: 1686

Cannot find .mdf file in App_data

I am creating a basic MVC application using Visual Studio 2013 to list details of employees.And I am not able to find the Employee.mdf file in the App_data folder even though I can create new records. Here is the list of steps I have followed.

  1. Created a new ASP.Net web application, by selecting the Empty template and MVC ticked.
  2. Created a Model file called Employee and an EmployeeDBContext class. Made the required change in the Web.config
  3. Added an MVC controller with Views using Entity Framework and selected the Model class. So after scaffolding I am provided with a controller with Create,Edit,Delete options. I am able to do all these functionality which basically means there is a datbase.

But I am not able to find the .mdf file under the App_data folder.Here is my code sample.

Employee Model:

namespace Test1.Models
{
public class Employee
{
    public int EmployeeId { get; set; }
    public string Name { get; set; }
    public string City { get; set; }
    public int Salary { get; set; }
}

public class EmployeeDBContext : DbContext
{
    public DbSet<Employee> Employees { get; set; }
}
}

Web.Config

<connectionStrings>
<add name="EmployeeDBContext"connectionString="Data Source=(LocalDB)\v11.0; AttachDbFilename=|DataDirectory|\Employees.mdf; 
Integrated Security=True" providerName="System.Data.SqlClient" />  </connectionStrings>

I have tried all the options provided in this solution Why is mdf file not appearing in the App_Data folder?

Upvotes: 0

Views: 2592

Answers (3)

mtareq
mtareq

Reputation: 181

Just if someone is still facing the problem, Run visual studio in debug mode and register a user and the mdf will be created in App_data.

Upvotes: 1

Hartur Barreto
Hartur Barreto

Reputation: 1

The folder App_Data wasn't there, then I created the folder and run the application (f5). The EF created the .mdf files without problem.

Upvotes: 0

Shah NIral
Shah NIral

Reputation: 440

Solution:

  1. In the Solution Explorer, click ‘show all files’.
  2. Then click the refresh button.
  3. Then expand the App_Data folder

Problem: The App_Data folder still doesn’t show anything.

Solution:

  1. F5 (Debug) the solution.
  2. Navigate to /Movies in IE- this step populates the database. You could also try using update-database in nuget package manager console.

Go back to visual studio and refresh the App_Data folder.

Upvotes: 0

Related Questions