Last post Dec 31, 2020 07:53 PM by firstname.lastname@example.org
Dec 31, 2020 03:35 AMemail@example.com|LINK
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.
MailingInfo MI = (MailingInfo)HttpContext.Current.Session["MailingInfo"];
using (IdentityProofContext dbContext = new IdentityProofContext())
MailingInfo IdData = dbContext.MailingInfo.Where(r => r.MailId == mId).FirstOrDefault();
if (IdData != null)
IdData.Compeletd = "Y";
IdData.FirstName = MI.FirstName;
IdData.LastName = MI.LastName;
IdData.StreetAddress = MI.StreetAddress;
IdData.City = MI.City;
IdData.State = MI.State;
IdData.Zip = MI.Zip;
IdData.PhoneNumber = MI.PhoneNumber;
any help will be highly appreciated.
Dec 31, 2020 08:19 AM|DA924|LINK
What you have done is how it is suppose to be done, plain and simply put.
Dec 31, 2020 09:56 AM|XuDong Peng|LINK
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.
Dec 31, 2020 07:53 PMfirstname.lastname@example.org|LINK
This is what I did to fix this:
MI.Compeletd = "Y";
MI.MailId = mId;
dbContext.Entry(MI).State = EntityState.Modified;