asp.net-mvc - 无法附加文件:FirstMVC.Models.EmployeeContext.mdf' 作为数据库'FirstMVC.Models.EmployeeContext'
问题描述
我收到此错误:
无法将文件“FirstMVC.Models.EmployeeContext.mdf”附加为数据库“FirstMVC.Models.EmployeeContext”
源错误:
第 19 行:员工 employee = empContext.Employee.Single(emp => emp.EID == id);
第 21 行:返回视图(员工);源文件:FirstMVC\Controllers\EmployeeController.cs
这是我的web.config
:
<connectionStrings>
<add name ="EmpolyeeContext"
connectionString="Data source=.; Initial Catalog=MVCPractice1; integrated security=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
员工控制器:
public ActionResult Details(int id)
{
EmployeeContext empContext = new EmployeeContext();
Employee employee = empContext.Employee.Single(emp => emp.EID == id);
return View(employee);
}
EmployeeContext.cs:
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employee { get; set; }
}
员工.cs:
[Table("tblEmployee")]
public class Employee
{
[Key]
public int EID { get; set; }
public string EName { get; set; }
public string EGender { get; set; }
public string ECity { get; set; }
}
到目前为止我尝试了什么:
更改数据库名称并测试与 ADO.Net 实体数据模型的连接。
提前致谢。
解决方案
推荐阅读
- r - 自动移除 R6 对象
- rust - 通过变量访问结构字段
- swift - Images.xcassets:1:1: Distill 因未知原因而失败
- javascript - 有人可以向我解释这个 JavaScript 切换代码吗?
- android - 创建样式化的 LinearLayout 自定义视图
- sql - Postgresql 11 - 按整数数组索引排序
- python - 给定火车系统的孤立节点与其非相邻节点之间的边距离,如何预测图形网络?
- javascript - Node.js 写入 CSV 文件
- html - 如何正确设置带有字母的复选框?
- java - 如何将 SharedPreferences 携带到同一活动的新功能中?(安卓工作室)