gpt4 book ai didi

c# - 使用 SubmitChanges() 时数据库中的字段未更新

转载 作者:行者123 更新时间:2023-11-30 23:10:34 25 4
gpt4 key购买 nike

我正在尝试使用数据库上下文更新数据库中的 2 个字段

 [HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ChangeDefaultUserLockingSetting(int PasswordAttempts, int DefaultLockingTime)
{
var defaultAccountSettings = new DefaultAccountSettingsDataContext();
var defaultLockoutTimeSpam = defaultAccountSettings.DefaultAccountSettings.Where(u=>u.id==1).Select(u=>u.DefaultAccountLockoutTimeSpan).First();
var maxFailedAccessAttemptsBeforeLockout = defaultAccountSettings.DefaultAccountSettings.Where(u => u.id == 1).Select(u=>u.MaxFailedAccessAttemptsBeforeLockout).First();

//foreach (int item in defaultLockoutTimeSpam)
{
defaultLockoutTimeSpam = DefaultLockingTime;
}

maxFailedAccessAttemptsBeforeLockout = DefaultLockingTime;

defaultAccountSettings.SubmitChanges();


return View("Index", loadAdministrationViewModel());
}

我做错了什么?

最佳答案

您需要尝试这段代码。

 [HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ChangeDefaultUserLockingSetting(int PasswordAttempts, int DefaultLockingTime)
{
var defaultAccountSettings = new DefaultAccountSettingsDataContext();
var defaultLockoutTimeSpam = defaultAccountSettings.DefaultAccountSettings.Where(u => u.id == 1).FirstOrDefault();
var maxFailedAccessAttemptsBeforeLockout = defaultAccountSettings.DefaultAccountSettings.Where(u => u.id == 1).FirstOrDefault();

//foreach (int item in defaultLockoutTimeSpam)
{
defaultLockoutTimeSpam.DefaultAccountLockoutTimeSpan = DefaultLockingTime;
}

maxFailedAccessAttemptsBeforeLockout.MaxFailedAccessAttemptsBeforeLockout = DefaultLockingTime;

defaultAccountSettings.SubmitChanges();


return View("Index", loadAdministrationViewModel());
}

关于c# - 使用 SubmitChanges() 时数据库中的字段未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45294845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com