简体   繁体   English

实体无法解析符号 SaveChanges

[英]Entity cannot resolve symbol SaveChanges

I just added an entity object to my project.我刚刚在我的项目中添加了一个实体对象。 When I go to savechanges, it is telling me that it is not found.当我去 savechanges 时,它告诉我找不到它。

Here is an example:下面是一个例子:

在此处输入图片说明

And the code:和代码:

[Authorize]
[SessionExpireFilter]
public ActionResult Delink()
{
  var control = Logging.StartLog();
  control.ClassName = System.Reflection.MethodBase.GetCurrentMethod().Name;

  try
  {
    if (CurrentCustomerSession.Current.AccountGuid == Guid.Empty)
    {
      Logging.WriteLog(control, "Redirecting to AddCustomer:Customer since CurrentAccountGuid == null");
      return RedirectToAction("AddCustomer", "Customer");
    }

    var username = System.Web.HttpContext.Current.User.Identity.Name.ToLower();
    var entities = new SuburbanPortalEntities();
    var qry = (from x in entities.UsersAccountLinks
               where x.AccountId == CurrentCustomerSession.Current.AccountGuid && x.aspnet_Users.LoweredUserName == username
      select x).FirstOrDefault();
    if(qry == null)
      return View("Error");

    qry.AccountId = Guid.Empty;
    entities.SaveChanges();
    CurrentCustomerSession.Current.AccountGuid = Guid.Empty;
    CurrentCustomerSession.Current.AccountNumber = string.Empty;
    CurrentCustomerSession.Current.Branch = string.Empty;
    //return View("");
    return RedirectToAction("AccountScreen", "Customer");
  }
  catch (Exception ex)
  {
    Logging.WriteLog(control, string.Format("exception: {0}", ex.Message));
    Logging.WriteException(control, ex);
    return View("Error");
  }
  finally
  {
    Logging.WriteLog(control, "End Delink");
    Logging.FlushLog(control);
  }
}

I'm not sure what to check at this point.我不确定此时要检查什么。 I have deleted SuburbanPortalEntities and readded it without any success.我删除了 SuburbanPortalEntities 并阅读了它,但没有成功。

Any suggestions where I look?我在哪里看的任何建议?

For future reference, I had 6.1.x installed of Entity Framework.为了将来参考,我安装了 Entity Framework 6.1.x。 When I checked the nuget packages, it showed 6.2.0 available.当我检查 nuget 包时,它显示 6.2.0 可用。 Once I updated to that version of Entity Framework, it started working correctly.一旦我更新到该版本的实体框架,它就开始正常工作。

我通过将 Entity Framework 版本从 6.2.0 降级到 6.1.0 再降回 6.2.0 解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM