在我的数据库中,有一个名为 tblEmp
的表。现在我在模型中创建了一个Employee
类。
using System.ComponentModel.DataAnnotations;
namespace MvcDemo.Models
{
[Table("tblEmp")]
public class Employee
{
public int Eid { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public int Did { get; set; }
}
}
我已经使用了using System.ComponentModel.DataAnnotations;
并且还添加了System.Data.Entity
,但它仍然显示:
Type or namespace name "table could not be found"
最佳答案
您在这里提供了错误的表名称[Table("tblUser")]
,它应该是[Table("tblEmp")]
。确保表(此处为 tblEmp
)中指定的列名称和数据类型与类(此处为 Employee
)的属性名称和数据类型相匹配。
关于.net - mvc中表名与类的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24009541/