Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:

C#
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);
        }
Posted
Updated 9-May-16 20:52pm
v3

1 solution

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900