Error-An exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code Additional information: One or more validation errors were detected during model generation: MVCApplication.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.
controller code:
namespace MVCApplication.Controllers
{
public class EmployeeController : Controller
{
// GET: Employee
public ActionResult Detail(int id)
{
EmployeeContext employeecontext = new EmployeeContext();
Employee emp = employeecontext.Employees.Single(x => x.Emp_Id ==id);//here its throwing an exception
return View("employee",emp);
}
}
this is my model employee class:
namespace MVCApplication.Models
{
[Table("Employee")]
public class Employee
{
public int Emp_Id { get; set; }
public string Emp_Name { get; set; }
public string Designation { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
}
}
this is my employee context class:
namespace MVCApplication.Models
{
public class EmployeeContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
}