实体类型'员工'没有定义键。定义此实体类型的键。员工:entitytype:entityset'employee'基于没有定义键的类型'employee'。 [英] Entitytype 'employee' has no key defined. Define the key for this entitytype. Employees: entitytype: entityset 'employees' is based on type 'employee' that has no keys defined.
问题描述
在模型生成期间检测到一个或多个验证错误:
mvcstarted.Models.employee :: EntityType'employee'没有定义键。定义此EntityType的密钥。
employees:EntityType:EntitySet; employees;基于类型;员工;没有定义键。
public ActionResult Details(int id)
{
employeecontext empt = new employeecontext();
employee emptt = empt.employees.Single(emp => emp.Emp_id == id);
返回查看(emptt);
}
我尝试过:
i到目前为止已经尝试了这么多时间,但问题仍然如上所述请告诉我我还能做些什么
One or more validation errors were detected during model generation:
mvcstarted.Models.employee: : EntityType 'employee' has no key defined. Define the key for this EntityType.
employees: EntityType: EntitySet;employees; is based on type;employee; that has no keys defined.
public ActionResult Details(int id)
{
employeecontext empt = new employeecontext();
employee emptt = empt.employees.Single(emp => emp.Emp_id== id);
return View(emptt);
}
What I have tried:
i have tried so much time until now but issue still arrising as above please suggest me what can i do further
推荐答案
查看我的博客 - EntityType:EntitySet'[Entity Name]'基于没有键定义的类型'[Entity Name]' Tadit Dash [ ^ ]
Check out my blog - EntityType: EntitySet ‘[Entity Name]’ is based on type ‘[Entity Name]’ that has no keys defined | Tadit Dash[^]
你需要做两件事(这与代码有关)第一种方法):
1-确定主键
You need to do two things(this is related to code first approach):
1- Determine the primary key
[Key]
public int BidYearID { get; set; }
2-你必须构建你的解决方案然后尝试添加视图
2- you have to build your solution then try to add the view
这篇关于实体类型'员工'没有定义键。定义此实体类型的键。员工:entitytype:entityset'employee'基于没有定义键的类型'employee'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!