Reputation: 952
I'm trying to create an one-to-one relationship between my AspNetUser (ApplicationUser class) table and my Employee table.
The problem is:
What I've tried:
Here is a example of what I expect to implement:
public class ApplicationUser : IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>
{
public ApplicationUser()
: base()
{
PreviousUserPasswords = new List<PreviousPassword>();
}
public virtual IList<PreviousPassword> PreviousUserPasswords { get; set; }
public virtual Employee Employee { get; set; }
}
[Table("EMPLOYEE")]
public class Employee
{
[Key, Column("ID")]
public int Id { get; set; }
[Column("ID_IDIOM")]
public int IdIdiom { get; set; }
[Column("USER_LOGIN")]
[Required]
[StringLength(50)]
public string UserName { get; set; }
[Column("NAME")]
[Required]
[StringLength(100)]
public string Name { get; set; }
[Column("EMAIL")]
[Required]
[StringLength(100)]
public string Email { get; set; }
[Column("ACTIVE")]
public bool Active { get; set; }
[Column("EMPLOYEE_TYPE")]
public short EmployeeType { get; set; }
[Column("SHOW_TUTORIAL")]
public bool ShowTutorial { get; set; }
public ApplicationUser User { get; set; }
}
Any idea will help a lot.
PS.: Sorry for my bad english.
Upvotes: 3
Views: 3578
Reputation: 12304
This can be configured with the fluent api if your application context inherits from IdentityDbContext:
modelBuilder.Entity<Employee>()
.HasRequired(e => e.User)
.WithRequiredDependent(u => u.Employee);
See https://msdn.microsoft.com/en-us/data/jj591620.aspx?f=255&MSPPError=-2147217396#RequiredToRequired
Upvotes: 4