Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 收到错误,说明无法将空值插入到';电子邮件确认';列';AspNetUsers';桌子_C#_Sql Server_Asp.net Mvc 5_Asp.net Identity - Fatal编程技术网

C# 收到错误,说明无法将空值插入到';电子邮件确认';列';AspNetUsers';桌子

C# 收到错误,说明无法将空值插入到';电子邮件确认';列';AspNetUsers';桌子,c#,sql-server,asp.net-mvc-5,asp.net-identity,C#,Sql Server,Asp.net Mvc 5,Asp.net Identity,我最近在数据库的AspNetUsers表中添加了一些新列(努力从Identity 1.0迁移到2.0)。我将“EmailConfirmed”列设置为可空,但在运行项目并登录时,我收到一个错误,说明:操作:LoginPartial控制器:帐户异常消息:“IdentityUser`4”上的“EmailConfirmed”属性无法设置为“null”值。必须将此属性设置为“System.Boolean”类型的非空值。 错误发生在Account Controller页面内的Login方法中。以下是一些代码

我最近在数据库的AspNetUsers表中添加了一些新列(努力从Identity 1.0迁移到2.0)。我将“EmailConfirmed”列设置为可空,但在运行项目并登录时,我收到一个错误,说明:操作:LoginPartial控制器:帐户异常消息:“IdentityUser`4”上的“EmailConfirmed”属性无法设置为“null”值。必须将此属性设置为“System.Boolean”类型的非空值。

错误发生在Account Controller页面内的Login方法中。以下是一些代码(它在用户变量的行处断开):

[HttpPost]
[异名]
[ValidateAntiforgeryTokenOnalPosts]

公共异步任务似乎更改了数据库类型,但没有更改模型类型

虽然您的表允许空值,但映射表的C#类不允许空值,它是“bool”而不是“bool”


如果您使用的是实体框架,则必须更改类型映射;否则,您将找到表示映射到表的模型的类,并更改“UserManager.FindAsync”方法返回的类型。

似乎您更改了数据库类型,但没有更改模型类型

虽然您的表允许空值,但映射表的C#类不允许空值,它是“bool”而不是“bool”


如果您使用的是实体框架,则必须更改类型映射;否则,您将找到表示映射到表的模型的类,并更改“UserManager.FindAsync”方法返回的类型到IdentityUser类。感谢您的输入。我通过在IdentityUser类中添加:public bool?EmailConfirmed{get;set;}来实现它。感谢您的输入。
[HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryTokenOnAllPosts]
    public async Task<ActionResult> Login(LoginViewModel model)
    {
        try
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);
                if (user != null)
                {
                    await SignInAsync(user, false);                        

                    return RedirectToAction("HomeIndex", "Home");
                }
                else
                {
                    TempData["ErrorMsg"] = "Incorrect email and/or password. Please try again...";
                }
            }
            // If we got this far, something failed, redisplay form

            return View("LoginPartial", model);
        }
        catch (Exception e)
        {
            HandleErrorInfo error = new HandleErrorInfo(e, "Account", "LoginPartial");
            return View("Error", error);
        }
    }