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.
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.MiddleName= MI.MiddleName;
IdData.LastName = MI.LastName;
IdData.StreetAddress = MI.StreetAddress;
IdData.City = MI.City;
IdData.State = MI.State;
IdData.Zip = MI.Zip;
IdData.PhoneNumber = MI.PhoneNumber;
dbContext.SaveChanges();any help will be highly appreciated.