Updating the existing row in a table with session data
Dec 31, 2020 03:35 AM|anjaliagarwal5@yahoo.com|LINK
Hello All,
I have an entire class object stored in my session. I want to update an existing row in a table with the session data. I am trying to find out if their any better way. In below code, I am trying to get the data from Session["MailingInfo"] and trying to
update the data in the existing table. I tried to do this:
IDData = MI
That didn't work so I tried this way and it worked. I was wondering if their is any simple way to achieve this or do I need to assign each property individually like so: IdData.FirstName = MI.FirstName and so on.
That didn't work so I tried this way and it worked. I was wondering if their is any simple way to achieve this or do I need to assign each property individually like so: IdData.FirstName = MI.FirstName and so on.
What you have done is how it is suppose to be done, plain and simply put.
If you find the post has answered your issue, then please mark post as 'answered'.
You could even delete old entity then add a new entity again. Of course, this will reduce work efficiency.
Best regards,
Xudong Peng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
505 Points
1259 Posts
Updating the existing row in a table with session data
Dec 31, 2020 03:35 AM|anjaliagarwal5@yahoo.com|LINK
Hello All,
I have an entire class object stored in my session. I want to update an existing row in a table with the session data. I am trying to find out if their any better way. In below code, I am trying to get the data from Session["MailingInfo"] and trying to update the data in the existing table. I tried to do this:
That didn't work so I tried this way and it worked. I was wondering if their is any simple way to achieve this or do I need to assign each property individually like so: IdData.FirstName = MI.FirstName and so on.
any help will be highly appreciated.
Contributor
4863 Points
4120 Posts
Re: Updating the existing row in a table with session data
Dec 31, 2020 08:19 AM|DA924|LINK
That didn't work so I tried this way and it worked. I was wondering if their is any simple way to achieve this or do I need to assign each property individually like so: IdData.FirstName = MI.FirstName and so on.
What you have done is how it is suppose to be done, plain and simply put.
Participant
1780 Points
553 Posts
Re: Updating the existing row in a table with session data
Dec 31, 2020 09:56 AM|XuDong Peng|LINK
Hi anjaliagarwal5,
According to your description and the code you provided, do you want to copy the attribute values of the class object to another object?
If this is the case, you could try to use some utils like MiscUtil in this case.
You could even delete old entity then add a new entity again. Of course, this will reduce work efficiency.
Best regards,
Xudong Peng
Member
505 Points
1259 Posts
Re: Updating the existing row in a table with session data
Dec 31, 2020 07:53 PM|anjaliagarwal5@yahoo.com|LINK
This is what I did to fix this:
dbContext.Attach(MI);
MI.Compeletd = "Y";
MI.MailId = mId;
dbContext.Entry(MI).State = EntityState.Modified;
dbContext.SaveChanges();