【问题标题】:Entity cannot resolve symbol SaveChanges实体无法解析符号 SaveChanges
【发布时间】:2018-05-03 13:59:30
【问题描述】:

我刚刚在我的项目中添加了一个实体对象。当我去 savechanges 时,它告诉我它没有找到。

这是一个例子:

还有代码:

[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);
  }
}

我现在不确定要检查什么。我已删除 SuburbanPortalEntities 并重新读取它,但没有任何成功。

有什么建议吗?

【问题讨论】:

  • “当我去 savechanges”,这是什么意思?您的意思是“当我使用调用 SaveChanges 编译我的代码时?”。或者你说的是导航?检查错误列表并发布确切的编译错误。 SuburbanPortalEntities 的班级是否没有错误?
  • 你在保存什么,查询返回 null 还是不喜欢空的 GUID 集?
  • 我无法编译,这是编译时错误。

标签: c# asp.net-mvc entity-framework-6


【解决方案1】:

为了将来参考,我安装了 6.1.x 的实体框架。当我检查 nuget 包时,它显示 6.2.0 可用。一旦我更新到那个版本的实体框架,它就开始正常工作了。

【讨论】:

    【解决方案2】:

    我通过将实体框架版本从 6.2.0 降级到 6.1.0 再降回 6.2.0 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 2016-05-24
      • 2016-12-31
      相关资源
      最近更新 更多