0

I want to update some of my columns value using entity framework My code is as follows

public static void UpdateData(string contentMenu, int eid) //Update data in database  
        {
            using (var context = new CmsContext())
            {
                try
                {
                    var objDataContent = new Content
                    {
                        MenuContent = contentMenu,
                        ModifiedDateTime = DateTime.Now
                    };
                   //Code to update only MenuContent and ModifiedDateTime whose id=eid
                    GetRecords();
                }
                catch (Exception ex)
                {
                    //
                }
            }
        }

There are lot of answers in S/O but none of them helped me. I followed https://stackoverflow.com/a/5567616/4701699

How can I update these two columns on the basis of id parameters like MSSQL query

update [CMS Menu].[dbo].[Contents] set MenuContent = 'testing' ,
ModifiedDateTime ='2016-01-02 16:02:15.803' where ContentId=2

1 Answer 1

2

You Can Update Your Column Entries by Using Linq:-

Here Are Example Code:-

var data = db.Content.FirstOrDefault(x=>x.ContentId==eID);
data.ModiFiedDateTime = DateTime.Now;
data.MenuContent = contentMenu;
db.SaveChanges();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.