EF Code First Multiplicity

时间:2017-11-08 17:47:08

标签: entity-framework ef-code-first

我有以下内容:

public class ApplicationUser : IdentityUser
    {
        public ApplicationUser()
        {

        }

        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }

        [ForeignKey("UserProfile")]
        public int UserProfileID { get; set; }

        public UserProfile UserProfile { get; set; }

    }
}



public class UserProfile : BaseModel
    {
        [Key]
        public int UserProfileID { get; set; }

        [Required]
        public String FirstName { get; set; }

        [Required]
        public String LastName { get; set; }

        public String LicenseNumber { get; set; }

        public String Position { get; set; }        

        public bool? Active { get; set; }

        [Required]
        [ForeignKey("ApplicationUser")]
        public String AppUserID { get; set; }

        public ApplicationUser ApplicationUser { get; set; }

        [ForeignKey("Division")]
        public int? DivisionID { get; set; }

        public virtual Division Division { get; set; }

        public virtual ICollection<Building> Buildings { get; set; }

        public virtual ICollection<UserProcess> UserProcesses { get; set; }

        public UserProfile()
        {
            Buildings = new HashSet<Building>();
        }

    }

我收到了错误

  

'UserProfile_ApplicationUser_Target :: Multiplicity无效   关系中的角色'UserProfile_ApplicationUser_Target'   'UserProfile_ApplicationUser'。因为Dependent Role属性   不是关键属性,是多重性的上界   依赖角色必须是'*'。“

我没有看到什么是错的。这应该是1:1的关系。 ApplicationUser具有userProfile,UserProfile始终具有applicationuser。我有它编码的方式使它成为一对多的关系,因为多个用户配置文件可以有一个ApplicationUser吗?我想在UserProfile上维护int键。

0 个答案:

没有答案