public class Role : IEntity
{
public int Id { get; set; }
public string Label { get; set; }
public User User { get; set; }
}
public class User : IEntity
{
public int Id { get; set; }
public string FirstName { get; set; }
public int RoleId { get; set; }
public Role Role { get; set; }
}
public void Configure(EntityTypeBuilder<Role> entity)
{
entity
.HasKey(key => key.Id);
entity
.Property(property => property.Label)
.HasDefaultValue("Customer")
.HasMaxLength(20)
.IsRequired();
entity
.HasOne(property => property.User)
.WithOne(property => property.Role)
.HasForeignKey<User>(property => property.RoleId);
}
public class Role : IEntity
{
public int Id { get; set; }
public string Label { get; set; }
public ICollection<User> Users { get; set; }
}
public class User : IEntity
{
public int Id { get; set; }
public string FirstName { get; set; }
public int RoleId { get; set; }
public Role Role { get; set; }
}
entity
.Property(property => property.Label)
.HasDefaultValue("Customer")
.HasMaxLength(20)
.IsRequired();