将Identity PK更改为int后:从实体化的“System.Int32”类型到“System.String”类型的指定强制转换无效

时间:2015-05-09 06:48:31

标签: asp.net asp.net-identity

使用Identity 2(VS 2015)的ASP.NET网站Web表单应用程序。使用标准模板生成的站点(都使用了字符串的Id),然后按教程将Users表的主键更改为Int,这就是问题开始的地方。出现EF正在登录时检索记录,但无法填充ApplicationUser对象。

如果重要的话,直接在SQL(非代码优先)中编辑用户表。尝试使用Id(Int)覆盖IdentityUser的Id(字符串)属性,但是编译器在不同的返回类型下进行空闲。建议?

Line 26:       **Dim user As ApplicationUser = manager.Find(Email.Text, Password.Text)**
Line 27:       If user IsNot Nothing Then

错误追踪:

[InvalidOperationException: The specified cast from a materialized 'System.Int32' type to the 'System.String' type is not valid.]
   System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +235
   lambda_method(Closure , Shaper ) +164
   System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +181
   System.Data.Entity.Core.Common.Internal.Materialization.<MoveNextAsync>d__4.MoveNext() +374
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Data.Entity.Internal.<FirstMoveNextAsync>d__0.MoveNext() +513
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Data.Entity.Infrastructure.<FirstOrDefaultAsync>d__25`1.MoveNext() +350
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +59
   Microsoft.AspNet.Identity.EntityFramework.<GetUserAggregateAsync>d__68.MoveNext() +346
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +59
   Microsoft.AspNet.Identity.<FindAsync>d__12.MoveNext() +272
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   Microsoft.AspNet.Identity.AsyncHelper.RunSync(Func`1 func) +281
   Microsoft.AspNet.Identity.UserManagerExtensions.Find(UserManager`2 manager, String userName, String password) +168
   Account_Login.LogIn(Object sender, EventArgs e) in C:\Users\Lauren\Documents\Visual Studio 2015\WebSites\Template\Account\Login.aspx.vb:26
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +109
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3449

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.6.57.0

0 个答案:

没有答案