‘AspNetUser’类型的属性’Claims’不是导航属性
我正在使用ASP.NET Identity 2.2。 我正在将ASP.NET旧成员身份迁移到新的身份系统。 我按照本文中提到的步骤执行迁移。
我扩展了IdentityUser
并添加了更多属性,如下所示:
public partial class AspNetUser : IdentityUser { public AspNetUser() { CreateDate = DateTime.Now; IsApproved = false; LastLoginDate = DateTime.Now; LastActivityDate = DateTime.Now; LastPasswordChangedDate = DateTime.Now; LastLockoutDate = DateTime.Parse("1/1/1754"); FailedPasswordAnswerAttemptWindowStart = DateTime.Parse("1/1/1754"); FailedPasswordAttemptWindowStart = DateTime.Parse("1/1/1754"); Discriminator = "AspNetUser"; LastModified = DateTime.Now; this.AspNetUserClaims = new HashSet(); this.AspNetUserLogins = new HashSet(); this.AspNetRoles = new HashSet(); } .... public virtual Application Application { get; set; } public virtual ICollection AspNetUserClaims { get; set; } public virtual ICollection AspNetUserLogins { get; set; } public virtual ICollection AspNetRoles { get; set; } }
AspNetUser
类中有更多属性,为简洁起见,不包括这些属性。
我能够使用身份系统成功注册用户:
var manager = new ApplicationUserManager(); var user = new AspNetUser { UserName = UserName.Text.Trim(), Email = Email.Text.Trim() }; var result = manager.Create(user, Password.Text);
但是,当我通过电子邮件地址/用户名搜索任何用户时,我得到一个例外:
var existingUser = manager.FindByEmail(emailAddress);
错误是:
The property 'Claims' on type 'AspNetUser' is not a navigation property. The Reference and Collection methods can only be used with navigation properties. Use the Property or ComplexProperty method.
更新:
如果我从AspNetUser
类中删除AspNetUserClaims
属性,那么我将获得一个新错误列表:
Schema specified is not valid. Errors: The relationship 'JanEntities.FK__AspNetU__Appli__628FA481' was not loaded because the type 'MyEntities.AspNetUser' is not available. The following information may be useful in resolving the previous error: The required property 'AspNetUserClaims' does not exist on the type 'SampleApp.Core.AspNetUser'. The relationship 'MyEntities.AspNetUserRole' was not loaded because the type 'MyEntities.AspNetUser' is not available. The following information may be useful in resolving the previous error: The required property 'AspNetUserClaims' does not exist on the type 'SampleApp.Core.AspNetUser'. The relationship 'MyEntities.FK_dbo_AspNetUserClaim_dbo_AspNetUser_User_Id' was not loaded because the type 'MyEntities.AspNetUser' is not available. The following information may be useful in resolving the previous error: The required property 'AspNetUserClaims' does not exist on the type 'SampleApp.Core.AspNetUser'. The relationship 'MyEntities.FK_dbo_AspNetUserLogin_dbo_AspNetUser_UserId' was not loaded because the type 'MyEntities.AspNetUser' is not available. The following information may be useful in resolving the previous error: The required property 'AspNetUserClaims' does not exist on the type 'SampleApp.Core.AspNetUser'.
以下是包含新ASP.NET标识表的数据库图:
任何人都可以帮我解决这个问题吗? 任何帮助都非常感谢。
您可以在此处查看IdentityUser的属性: https : //msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identityuser_properties(v = vs.108).aspx
如您所见,声明,登录,角色等属性已经存在。 默认情况下,asp.net标识使用DbContext,它inheritance自IdentityDbContext https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identitydbcontext%28v=vs.108%29.aspx
这个类配置很多东西,比如表映射等。我们能看到你的DbContext吗?
首先,尝试从构造函数中删除添加的ICollections和他们的初始值设定项。
- 使用带有Asp.net Identity 1.1 Alpha的Guid和自定义表名创建自定义实现
- 将asp.net MVC从5.0.0-beta2更新为5.0.0-rc1
- 如何检查用户在asp.net身份中有很多角色
- 在ASP.Net Identity(MVC)中的“注册”期间保存其他配置文件数据
- ASP.NET Core Identity 3 Cookie超时
- 使用结构图dependency injection时,“没有注册IUserTokenProvider”
- 更改Asp.net标识的主键和GetUserID
- 在ASP.Net MVC 5应用程序中使用多个ASP Identity 2.0
- 如何首先使用代码在已创建的数据库中创建ASP.net身份表?