如何更新实体框架中的行6。 [英] How to update row in entity framework 6.

查看:88
本文介绍了如何更新实体框架中的行6。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新包含许多列的实体行。

我们不能直接修改或简单的方法更新行。



我尝试了什么:



I need to update entity row with many columns on it.
Can't we modify directly or simple method to update the row.

What I have tried:

public static GlobalMessage ModifyCMEmailType(CMEmailType cMEmailType)
        {
            if (cMEmailType != null)
            {
                try
                {
                    var e = Db.CMEmailTypes.Where(p => p.CMEmailTypeId == cMEmailType.CMEmailTypeId).SingleOrDefault();
                    e.EmailType = cMEmailType.EmailType;
..
..
..
..
..
..
..



                    Db.SaveChanges();
                    return new GlobalMessage("", GlobalEnum.MessageStatus.Success, GlobalEnum.MessageCss.Success);
                }
                catch (Exception ex)
                {
                    ErrorWriter.WriteError(ex, "FunctionName --> InsertTable", "");
                }
            }
            return new GlobalMessage("", GlobalEnum.MessageStatus.Error, GlobalEnum.MessageCss.Error);
        }

推荐答案

Now it depends on if you want to update entire row or what. Usually we assign properties like you are doing but we can also assign whole object to fetched object like
              e = cMEmailType;
but do need to update the ID again.


这篇关于如何更新实体框架中的行6。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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