我正在使用Visual Studio 2013创建一个基本的MVC应用程序,以列出员工的详细信息。而且即使我可以创建新记录,我也无法在App_data文件夹中找到Employee.mdf文件。 以下是我所遵循的步骤列表。在App_data中找不到.mdf文件
- 创建一个新的ASP.Net Web应用程序,通过选择空模板和MVC打勾。
- 创建一个名为Employee和EmployeeDBContext类的模型文件。在Web.config中进行所需的更改
- 使用实体框架添加了具有视图的MVC控制器并选择了Model类。所以脚手架后,我提供了一个控制器与创建,编辑,删除选项。我能够完成所有这些基本上意味着存在数据库的功能。
但是我无法在App_data文件夹下找到.mdf文件。这里是我的代码示例。
员工型号:
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>
我曾尝试在该解决方案Why is mdf file not appearing in the App_Data folder?
你有没有试过在文件系统中检查文件夹本身(在Visual Studio之外)? –
@NemanjaTodorovic我没看看相应的文件夹,但在那里找不到它 – TheFallenOne
在这里寻找可能的解决方案,特别是在'IIS'设置下这应该可以帮助你http://stackoverflow.com/questions/528858/what-is-app-data-folder-used-for-in-visual-studio并且阅读这个以及它将解释文件夹以及它们是什么以及做什么.. - https:/ /msdn.microsoft.com/en-us/library/ex526337(v=vs.100).aspx – MethodMan