我刚刚在我的项目中添加了一个实体对象。当我去保存更改时,它告诉我它没有找到。
以下是一个例子:
代码:
[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,但没有成功读取它。
我看的任何建议?
答案 0 :(得分:1)
为了将来参考,我安装了6.1.x的Entity Framework。当我检查nuget包时,它显示6.2.0可用。一旦我更新到该版本的Entity Framework,它就开始正常工作了。
答案 1 :(得分:1)
我通过将Entity Framework版本从6.2.0降级到6.1.0并降级到6.2.0来解决了这个问题。