Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

How to create Foreign key in EF Code First for AspNetUser Table created by Identity

$
0
0

I have the following code: 

public class ApplicationUser : IdentityUser    {        [StringLength(30, ErrorMessage="First Name should not exceed 30 characters")]        [Required(ErrorMessage = "Please enter your First Name")]        public string FirstName { getset; }        [StringLength(30, ErrorMessage = "Last Name should not exceed 30 characters")]        [Required(ErrorMessage = "Please enter your Last Name")]        public string LastName { getset; }        public virtual ICollection<Document> Documents { getset; }        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)        {            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType            var userIdentity = await manager.CreateIdentityAsync(thisDefaultAuthenticationTypes.ApplicationCookie);            // Add custom user claims here            return userIdentity;        }    }    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>    {        public ApplicationDbContext()            : base("DefaultConnection", throwIfV1Schema: false)        {        }        public static ApplicationDbContext Create()        {            return new ApplicationDbContext();        }        public DbSet<Document> Documents { getset; }           }

public partial class Document
{    public int DocumentId { getset; }    [MaxLength(2000)]    public string DocumentUrl { getset; }    public bool IsReadyForApproval { getset; }    public DateTime CreateTime { getset; }    [DisplayFormat(DataFormatString = "{0:dd-MM-yy}",ApplyFormatInEditMode = true)]    public DateTime UpdateTime { getset; }    public Guid CreatorUserId { getset; }    [StringLength(100,ErrorMessage="Title should not exceed 100 characters")]    public string Title { getset; }    [StringLength(20)]    public string Department { getset; }    [StringLength(20)]    public string Complexity { getset; }    public bool IsVerified { getset; }    public virtual ApplicationUser ApplicationUser { getset; }
}

Can anyone provide me an easy solution for this problem?


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>