I have a MVC 5 application, which uses the Default Identity authentication.
The user profile is part of our model, which means that there are several class which have a foreign key to the UserInfo.
There are 2 DbContext, one for the model and another for the UserInfo.
public class ApplicationDbContext : IdentityDbContext<UserInfo>
{
public ApplicationDbContext()
: base("Profile")
{
}
}
public class UserInfo : IdentityUser
{
public UserInfo ()
{
LibraryItems = new List<LibraryItem>();
if (UserGroup == UserGroupEnum.ANALYST)
{
Companies = new List<Company>();
}
DateCreate = DateTime.Now;
DateUpdate = DateTime.Now;
DateDelete = DateTime.Now;
}
[DisplayColumnInIndex]
[DisplayName("Is Active ?")]
public bool IsActive { get; set; }
[Timestamp]
public byte[] RowVersion { get; set; }
//[ValidateFile(ErrorMessage = "Please select a PNG image smaller than 1MB")]
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[Editable(false, AllowInitialValue = true)]
public DateTime DateCreate { get; set; }
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime DateUpdate { get; set; }
//[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime DateDelete { get; set; }
[DisplayColumnInIndex]
public String Name { get; set; }
[DisplayColumnInIndex]
public String FirstName { get; set; }
[DisplayColumnInIndex]
public String Pseudo { get; set; }
[DisplayColumnInIndex]
public string PhoneNumber { get; set; }
[DisplayColumnInIndex]
public String Company { get; set; }
[DisplayName("Name_Id")]
[ForeignKey("FullName")]
public int? NameId { get; set; }
[DisplayColumnInIndex]
public UserGroupEnum UserGroup { get; set; }
[DisplayColumnInIndex]
public UserStatusEnum UserStatus { get; set; }
public virtual Name FullName { get; set; }
}
public class Comment
{
// more properties
[DisplayName("UserInfoId")]
[ForeignKey("UserInfo")]
public virtual String UserInfoId { get; set; }
}
public class Like
{
// more properties
[DisplayName("UserInfoId")]
[ForeignKey("UserInfo")]
public virtual String UserInfoId { get; set; }
}
My userInfo has also foreign keys to the the other tables of the second DBontext.
What is the best way to design our authentication system? and maintain the relationship between the two contexts.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…