如何解决EntityFramework.SqlServer.dll中发生的'System.Data.Entity.Core.EntityCommandExecutionException'但未在用户代码中处理异常 [英] How to solve 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code Exception

查看:144
本文介绍了如何解决EntityFramework.SqlServer.dll中发生的'System.Data.Entity.Core.EntityCommandExecutionException'但未在用户代码中处理异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MVC应用程序



我的控制器操作方法在哪里



  public   class  EmployeeController:Controller 
{

public ActionResult Index( int Id)
{
Employee_Context Emp = new Employee_Context();

Employee_Details Emp_Detail = Emp.Employee。 Single (emp = > \\ temp .id == Id);
return 查看(Emp_Detail);
}
}





我的型号



  public   class  Employee_Context:DbContext 
{
public DbSet< Employee_Details>员工{获取; set ; }

}





  namespace  MvC_Demo1.Models 
{
[表( Ëmployee)]
public class Employee_Details
{
public int id { get ; set ; }
public string 名称{ get ; set ; }
public string 名称{ get ; set ; }
}
}





我的ViewModel



 @ model MvC_Demo1.Models.Employee_Details 


@ {
ViewBag.Title =Index;
}

< div style = font -style:斜体 >
< h2 > 员工详细信息< / h2 >
< 表格 >
< tr >
< td > Id < / td >
< td > @ Model.id < / td >
< / tr >
< tr >
< span class =code-keyword>< td > 名称 < / td >
< td > @ Model.Name < / td >

< / tr >
< tr >
< td > 名称 < / td >
< td > @ Model.Designation < / td >

< / tr >

< / table >
< / div >







我在控制器操作方法中获取此操作,我在下面提到了



Employee_Details Emp_Detail = Emp.Employee.Single(emp => emp.id == Id);





请给出一个新的MVC解决方案

解决方案





检查你是否正确输入了目标表名,我不确定问题是否与它有关但是我发现您在指定目标表名时可能输错了特殊字符(Ë)。



尝试更改数据注释[表(Ëmployee)]表(员工)]



问候,







Jose N. Estrella


在web配置中检查你的连接字符串我也得到了同样的错误,因为连接字符串不是想要的

您好,



您的某些数据库实体不匹配。请检查此方法中使用的数据库实体。



对于ref: c# - System.Data.Entity.Core.EntityCommandExecutionException在MVC应用程序中发生使用EF [ ^ ]



谢谢


My MVC Application

Where my Controller action method is

public class EmployeeController : Controller
    {

        public ActionResult Index(int Id)
        {
            Employee_Context Emp = new Employee_Context();

            Employee_Details Emp_Detail = Emp.Employee.Single(emp => emp.id == Id);
            return View(Emp_Detail);
    }
}



My Model

public class Employee_Context : DbContext
   {
       public DbSet<Employee_Details> Employee { get; set; }

   }



namespace MvC_Demo1.Models
{
     [Table("Ëmployee")]
    public class Employee_Details
    {
        public int id { get; set; }
        public string Name { get; set; }
        public string Designation { get; set; }
    }
}



My ViewModel

@model MvC_Demo1.Models.Employee_Details


@{
    ViewBag.Title = "Index";
}

<div style="font-style:italic">
    <h2>Employee Details</h2>
    <table>
        <tr>
            <td>Id</td>
            <td>@Model.id</td>
        </tr>
        <tr>
            <td>Name</td>
            <td>@Model.Name</td>

        </tr>
        <tr>
            <td>Designation</td>
            <td>@Model.Designation</td>

        </tr>

    </table>
</div>




am getting this Execption in Controller action method which I mentioned it below

Employee_Details Emp_Detail = Emp.Employee.Single(emp => emp.id == Id);


Please give a solution for this am new to MVC

解决方案

Hi,

Check if you have typed correctly the target table name, I am not sure if the issue is related to it but I see that you may have mistyped a special char (Ë) while specifying the target table name.

Try changing Data Annotation [Table("Ëmployee")] for [Table("Employee")]

Regards,



Jose N. Estrella


Check Your Connection string in web config i am also getting the same error it is due to the Connection string was not as want


Hello,

Some of your database entity is mismatching. Please check the db entities being used in this method.

For ref: c# - System.Data.Entity.Core.EntityCommandExecutionException Occurred in MVC app Using EF[^]

Thanks


这篇关于如何解决EntityFramework.SqlServer.dll中发生的'System.Data.Entity.Core.EntityCommandExecutionException'但未在用户代码中处理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆