【发布时间】:2015-05-23 00:22:20
【问题描述】:
我在 Asp.net MVC 5 中的 UserManager 类属于以下类型
public UserManager<ApplicationUser<MyUser>> UserManager { get; private set; }
在运行时类型是 ;
{Microsoft.AspNet.Identity.UserManager<app.Models.ApplicationUser<MyCustom.DataAccessLayer.MyUser>>}
当我执行 findAsync 进行身份验证时。
var user = await UserManager.FindAsync(model.UserName, model.Password);
然后抛出异常 System.InvalidOperationException。因为它不是在寻找 MyUser 实体,所以它寻找 ApplicationUser1 实体。
The entity type ApplicationUser1 is not part of the model for the current context.
at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Where[TSource](IQueryable1 source, Expression1 predicate)
at Microsoft.AspNet.Identity.EntityFramework.UserStore1.FindByNameAsync(String userName)
at Microsoft.AspNet.Identity.UserManager1.<FindByNameAsync>d__d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.AspNet.Identity.UserManager1.<FindAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
【问题讨论】:
标签: asp.net-mvc-5 entity-framework-6 asp.net-identity