条目属性实体fremwork中的错误 [英] Entry property Error in entity fremwork

查看:53
本文介绍了条目属性实体fremwork中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用 var  dbCtx =  new  EmployeeEntities())
{
// 标记实体修改后的
dbCtx.Entry(stud).State = System.Data.EntityState.Modified;
dbCtx.SaveChanges();
}



如果在Entitties中设置属性Entry,则显示错误。

所以我不知道..

如何显示错误。



 私人  void 保存()
{

EmployeeMast objEmp = EmployeeMast ();

objEmp.EmpName = txtName.Text.Trim();
objEmp.EmpAdd = txtAddress.Text.Trim();
// objEmp.EmpBDate = Convert.ToDateTime(txtBDay.Text.Trim());
objEmp.EmpDept = Convert.ToInt32(drpDepartment.SelectedValue);

if (ViewState [ EmpId] == null
{
obj.EmployeeMasts.AddObject(objEmp);
obj.SaveChanges();
}
else
{
objEmp.EmpId = 1 ;
obj.Entry(objEmp).State = System.Data.EntityState.Modified;
obj.SaveChanges();
}
}
如果我是更新记录然后写代码 this 线。

obj.Entry(objEmp).State = System.Data.EntityState.Modified;
然后 条目不是 set ..错误显示。

解决方案

在编辑部分,您必须附加修改后的对象如下。



 obj.EmployeeMasts.Attach(objEmp); 





For更多信息:如何使用Entity Framework进行更新


using (var dbCtx = new EmployeeEntities())
        {
            //Mark entity as modified
            dbCtx.Entry(stud).State = System.Data.EntityState.Modified;
            dbCtx.SaveChanges();
        }


If am set property "Entry" in Entitties then display error.
So i have not any idea ..
How Display Error.

private void Save()
    {

        EmployeeMast objEmp = new EmployeeMast();

        objEmp.EmpName = txtName.Text.Trim();
        objEmp.EmpAdd = txtAddress.Text.Trim();
        // objEmp.EmpBDate = Convert.ToDateTime(txtBDay.Text.Trim());
        objEmp.EmpDept = Convert.ToInt32(drpDepartment.SelectedValue);

        if (ViewState["EmpId"] == null)
        {
            obj.EmployeeMasts.AddObject(objEmp);
            obj.SaveChanges();
        }
        else
        {
            objEmp.EmpId = 1;
            obj.Entry(objEmp).State = System.Data.EntityState.Modified;
            obj.SaveChanges();
        }
    }
if i am update record then write code this line.

obj.Entry(objEmp).State = System.Data.EntityState.Modified;
then "Entry" not set ..Error display.

解决方案

On edit section you have to attach the modified object is as below.

obj.EmployeeMasts.Attach(objEmp);



For more info : How to update using Entity Framework


这篇关于条目属性实体fremwork中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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