Plz帮我解决这个问题 [英] Plz Help me to fix the issue
本文介绍了Plz帮我解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道为什么我会收到此错误
执行命令定义时发生错误请参阅内部异常详细信息
I dont know why i am getting this error
an error occurred while executing the command definition see the inner exception-for-details
Department.cs
-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace Gen_HyperlinkByActionlink.Models
{
[Table("Departments")]
public class Department
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public int DeptNo { get; set; }
public List<Employee> Employees { get; set; }
}
}
EMployee.cs
-------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Gen_HyperlinkByActionlink.Models
{
[Table("Employee")]
public class Employee
{
[Key]
public int Employee_Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string City { get; set; }
public int DepartmentId { get; set; }
}
}
--------------
EmployeeContext.cs
namespace Gen_HyperlinkByActionlink.Models
{
public class EmployeeContext:DbContext
{
public DbSet<Employee> Employees { get; set; }
public DbSet<Department> Departments { get; set; }
}
}
-----------------------
EmployeeController
-------------------
public class EmployeeController : Controller
{
EmployeeContext employeeContext = new EmployeeContext();
//
// GET: /Employee/
public ActionResult Details(int id)
{
Employee employee = employeeContext.Employees.Single
(eid => eid.Employee_Id == id);
return View(employee);
}
public ActionResult DashBoard(int departmentID)
{
List<Employee> employees =
(employeeContext.Employees.Where(emp => emp.DepartmentId ==
departmentID)).ToList();
return View(employees);
}
}
-----------------------------------
Department Controller
----
public class DepartmentController : Controller
{
EmployeeContext employeeContext = new EmployeeContext();
//
// GET: /Department/
public ActionResult Index()
{
List<Department> Departments =
employeeContext.Departments.ToList();
return View(Departments);
}
}
--------------
推荐答案
请参阅我对该问题的评论。因此,只需使用调试器和/或日志记录,捕获异常并检查内部异常。如果使用日志记录执行此操作,则可能需要递归地转到所有内部异常。请参阅:
https://msdn.microsoft.com/en-us/library/system.exception.innerexception%28v=vs.110%29.aspx [ ^ ]。
-SA
Please see my comment to the question. So, just use the debugger and/or logging, catch the exception and examine the inner exception. If you do this using logging, you might need to go to all inner exceptions recursively. Please see:.
https://msdn.microsoft.com/en-us/library/system.exception.innerexception%28v=vs.110%29.aspx[^].
—SA
这篇关于Plz帮我解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文