0

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?

Community
  • 1
  • 1
TheFallenOne
  • 1,598
  • 2
  • 23
  • 57
  • Have you tried to check in folder itself in file system (outside of visual studio)? – Nemanja Todorovic Mar 03 '16 at 20:38
  • @NemanjaTodorovic I did look into the corresponding folder, but could not find it over there – TheFallenOne Mar 03 '16 at 20:41
  • look here for a the possible solutions especially the one under the `IIS` settings this should help you http://stackoverflow.com/questions/528858/what-is-the-app-data-folder-used-for-in-visual-studio and read this one as well it will explain the folder(s) and what they are as well as do.. - https://msdn.microsoft.com/en-us/library/ex526337(v=vs.100).aspx – MethodMan Mar 03 '16 at 20:48

3 Answers3

1

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.

mtareq
  • 171
  • 2
  • 4
0

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.

Shah NIral
  • 420
  • 5
  • 15
0

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.