该物业的债权“的类型”AspNetUser'不是一个导航属性 [英] The property 'Claims' on type 'AspNetUser' is not a navigation property

查看:365
本文介绍了该物业的债权“的类型”AspNetUser'不是一个导航属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET 2.2的身份。我迁移旧ASP.NET成员新的标识系统。我下面这。文章执行迁移

I'm using ASP.NET Identity 2.2. I'm migrating the ASP.NET old membership to new Identity system. I am following the steps mentioned in this article for performing the migration.

我已经延长 IdentityUser ,并添加一些更多的属性,如如下:

I have extended IdentityUser and added few more properties like follows:

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<AspNetUserClaim>();
            this.AspNetUserLogins = new HashSet<AspNetUserLogin>();
            this.AspNetRoles = new HashSet<AspNetRole>();
        }
        ....
        public virtual Application Application { get; set; }
        public virtual ICollection<AspNetUserClaim> AspNetUserClaims { get; set; }
        public virtual ICollection<AspNetUserLogin> AspNetUserLogins { get; set; }
        public virtual ICollection<AspNetRole> AspNetRoles { get; set; }

}

有在<$ C $几个特性C> AspNetUser 这是不包括为简便起见类。

There are few more properties in the AspNetUser class which is not included for brevity.

我能够成功注册的用户使用识别系统:

I am able to register the user successfully using the identity system:

 var manager = new ApplicationUserManager();
 var user = new AspNetUser
                {
                    UserName = UserName.Text.Trim(),
                    Email = Email.Text.Trim()
                };

 var result = manager.Create(user, Password.Text);



但是,当我搜索电子邮件地址的任何用户/用户名,然后我得到一个异常

But when I'm searching for any user by email address/username then I'm getting an exception:

var existingUser = manager.FindByEmail(emailAddress);



该错误是:

The error is:

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 属性类,然后我得到新的错误列表:

Update:

If I'm removing the AspNetUserClaims property from the AspNetUser class then I'm getting a list of new errors:

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身份表的数据库图:
< IMG SRC =http://i.stack.imgur.com/FLNKq.pngALT =在这里输入的形象描述>

The following is the database diagram which contains the new ASP.NET identity tables:

谁能帮我解决这个问题?任何帮助高度赞赏。

Can anyone help me to fix this issue? Any help is highly appreciated.

推荐答案

您可以在这里查看IdentityUser的属性:的 https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity .entityframework.identityuser_properties(v = vs.108)的.aspx

You can check here properties of IdentityUser: https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identityuser_properties(v=vs.108).aspx

正如你所看到的一样,索赔,登录属性,角色已经存在。
默认情况下asp.net同一性使用的DbContext,它从IdentityDbContext的 https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identitydbcontext%28v=vs.108%29.aspx

As you can see, properties like Claims, Logins, Roles are already there. By default asp.net identity is using DbContext, which inherits from IdentityDbContext https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identitydbcontext%28v=vs.108%29.aspx

本类配置如表映射等许多事情我们可以看到你的DbContext?

This class configure many things like table mappings etc. Can we see your DbContext?

因此,首先尝试删除添加ICollections和构造他们的初始化。

So first, try removing added ICollections and theirs initializers from constructor.

这篇关于该物业的债权“的类型”AspNetUser'不是一个导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆