title: How to update a record using LINQ LAMBDA in my ASP.NET MVC 5 Project
body: <p>I am new to entity framework and LINQ. I am stuck at an issue where I need to firstly check if the record already exists, if it exists then I need to update the record with column <strong>RESUMEID</strong> accordingly. If not then I need to add the record. I am able to add successfully but I don't know how to update the record in LINQ.</p>
  
  <p>Below is my attempt:</p>
  
  <pre><code>[HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(ReferralViewModel viewModel)
      {
          var candidateId = User.Identity.GetUserId();
           // I AM CONFUSED ABOUT BELOW STATEMENT
          var IsDupeReferral = _context.Referrals
         .Where(r =&gt; (r.CandidateId == candidateId)
        &amp;&amp; (r.CompanyId == viewModel.CompanyId) &amp;&amp; (r.SkillId == viewModel.SkillId))
        .Select(r=&gt;r.ReferralId).SingleOrDefault();
  
          if(IsDupeReferral!=0)
          {
            //IF I FIND DUPE REFERRAL RECORD I WANT TO UPDATE SOME OF THE VALUES IN THAT
                    _context.Referrals.Where(r =&gt; r.ReferralId == IsDupeReferral).
               AND UPDATE r.resumeId with viewModel.ResumeId // How to do this?
               // NOT SURE ABOUT BELOW LINE EITHER
              _context.SaveChanges();
          }
          else
          {
             // BELOW CODE IS WORKING FINE
              var referral = new Referral
              {
                  ReferralName = viewModel.ReferralName,
                  ResumeId = viewModel.ResumeId,
                  CandidateId = candidateId,
                  DegreeId = viewModel.DegreeId,
                  CoverLetterId = viewModel.CoverLetterId,
                  SkillId = viewModel.SkillId
              };
  
              if (!string.IsNullOrEmpty(viewModel.TempCompany))
              {
                  var newCompany = new Company
                  {
                      CompanyName = viewModel.TempCompany
                  };
                  newCompany.Referrals.Add(referral);
                  _context.Companies.Add(newCompany); ;
              }
              else
              {
                  referral.CompanyId = viewModel.CompanyId.Value;
                  _context.Referrals.Add(referral);
              }
              _context.SaveChanges();
          }
  
          return RedirectToAction("ReferralCenter");
      }
  </code></pre>