C# ASP.Net标识自定义字段在创建用户时丢失值

C# ASP.Net标识自定义字段在创建用户时丢失值,c#,asp.net-mvc-5,asp.net-identity,C#,Asp.net Mvc 5,Asp.net Identity,因此,我对MVC5、EF6和ASP.Net标识有一个有趣的问题。我已向ApplicationUser添加了一个自定义字段,但当我尝试使用UserManager.CreateAsync()创建新用户时,出现以下错误: “ApplicationUser”上的“IsConfiged”属性无法设置为“null”值。必须将此属性设置为“System.Boolean”类型的非空值 注意:调试时,user.IsConfirmed不为null的值应为false 有关守则如下: ApplicationUser u

因此,我对MVC5、EF6和ASP.Net标识有一个有趣的问题。我已向ApplicationUser添加了一个自定义字段,但当我尝试使用UserManager.CreateAsync()创建新用户时,出现以下错误:

“ApplicationUser”上的“IsConfiged”属性无法设置为“null”值。必须将此属性设置为“System.Boolean”类型的非空值

注意:调试时,user.IsConfirmed不为null的值应为false

有关守则如下:

ApplicationUser user = new ApplicationUser()
{
     UserName = model.UserName,
     Email = model.Email,
     ConfirmationToken = confirmationToken,
     IsConfirmed = false
};

IdentityResult result = await UserManager.CreateAsync(user, model.Password);
以及应用程序用户的定义:

public class ApplicationUser : IdentityUser
{
     public string Email { get; set; }
     public string ConfirmationToken { get; set; }
     public bool IsConfirmed { get; set; }
}
最后,堆栈跟踪:

[ConstraintException: The 'IsConfirmed' property on 'ApplicationUser' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.Boolean'. ]
   System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +152
   System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling(Int32 ordinal, String propertyName, String typeName) +95
   lambda_method(Closure , Shaper ) +1007
   System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +737
   lambda_method(Closure , Shaper ) +501
   System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +281
   System.Data.Entity.Core.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +105
   System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +52
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +164
   System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1(IEnumerable`1 sequence) +83
   System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +107
   System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +197
   System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +149
   System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) +251
   Microsoft.AspNet.Identity.EntityFramework.UserStore`1.FindByNameAsync(String userName) +1174
   Microsoft.AspNet.Identity.<FindByNameAsync>d__d.MoveNext() +231
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.AspNet.Identity.<ValidateUserName>d__0.MoveNext() +832
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   Microsoft.AspNet.Identity.<ValidateAsync>d__4.MoveNext() +433
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.AspNet.Identity.<CreateAsync>d__0.MoveNext() +629
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.AspNet.Identity.<CreateAsync>d__10.MoveNext() +883
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   L33THub.Web.Controllers.<Register>d__d.MoveNext() in c:\Users\rwn\Documents\Visual Studio 2013\Projects\L33THub\L33THub.Web\Controllers\AccountController.cs:121
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +61
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +117
   System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +323
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514812
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
[约束异常:“ApplicationUser”上的“IsConfiged”属性无法设置为“null”值。必须将此属性设置为“System.Boolean”类型的非null值。]
System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader,Int32序号)+152
System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueRorHandling(Int32序数,字符串propertyName,字符串typeName)+95
lambda_法(闭合、整形)+1007
System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 ConstructionEntityDelegate,EntityKey EntityKey,EntitySet EntitySet)+737
lambda_法(闭包、整形器)+501
System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper-Shaper)+281
System.Data.Entity.Core.Common.Internal.Materialization.SimpleNumerator.MoveNext()+105
System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()+52
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1源)+164
System.Data.Entity.Core.Objects.Elink.ObjectQueryProvider.b__1(IEnumerable`1序列)+83
System.Data.Entity.Core.Objects.elink.ObjectQueryProvider.ExecuteSingle(IEnumerable`1查询,表达式queryRoot)+107
System.Data.Entity.Core.Objects.elink.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(表达式)+197
System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(表达式)+149
System.Linq.Queryable.FirstOrDefault(IQueryable`1 source)+251
Microsoft.AspNet.Identity.EntityFramework.UserStore`1.FindBynameAAsync(字符串用户名)+1174
Microsoft.AspNet.Identity.d_ud.MoveNext()+231
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
Microsoft.AspNet.Identity.d_u0.MoveNext()+832
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter.GetResult()+21
Microsoft.AspNet.Identity.d_u4.MoveNext()+433
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
Microsoft.AspNet.Identity.d_u0.MoveNext()+629
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
Microsoft.AspNet.Identity.d_u10.MoveNext()+883
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
c:\Users\rwn\Documents\Visual Studio 2013\Projects\L33THub\L33THub.Web\Controllers\AccountController.cs:121中的L33THub.Web.Controllers.d\uu d.MoveNext()文件
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter.GetResult()+21
System.Threading.Tasks.TaskHelperExtensions.ThrowIfFaulted(任务)+61
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+114
System.Web.Mvc.Async.c__显示类37.b__36(IAsyncResult asyncResult)+66
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+136
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3f()+117
System.Web.Mvc.Async.c__显示类48.b__41()+323
System.Web.Mvc.Async.c__显示类33.b__32(IAsyncResult asyncResult)+44
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+136
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+50
System.Web.Mvc.Async.c__显示类2b.b__1c()+72
System.Web.Mvc.Async.c__显示类21.b__1e(IAsyncResult asyncResult)+185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+133
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+40
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)