Сопоставить один и тот же пользовательский объект с одним назначением для разных целей - PullRequest
0 голосов
/ 25 марта 2020

В моем случае у меня есть платформа Dogsitter, в которой есть встречи как для владельцев, так и для собак. Но поскольку я использую аутентификацию отдельных пользователей, у меня есть таблицы AspNetCoreUsers и AspNetCoreUsersRoles и один пользователь приложения.

public class ApplicationUser : IdentityUser, IAuditInfo, IDeletableEntity
{
    public ApplicationUser()
    {
        // Application user
        this.Id = Guid.NewGuid().ToString();
        this.Roles = new HashSet<IdentityUserRole<string>>();
        this.Claims = new HashSet<IdentityUserClaim<string>>();
        this.Logins = new HashSet<IdentityUserLogin<string>>();

        // Owner/Dogsitter info
        this.Comments = new HashSet<Comment>();
        this.Dogs = new HashSet<Dog>();
        this.Appointments = new HashSet<Appointment>();
    }

    public string FirstName { get; set; }

    public string MiddleName { get; set; }

    public string LastName { get; set; }

    public string FullName => this.FirstName + this.MiddleName + this.LastName;

    public string ImageUrl { get; set; }

    public decimal Rating { get; set; }

    public string Address { get; set; }

    public string SelfDescription { get; set; }

    public string DogsDescription { get; set; }

    public decimal WageRate { get; set; }

    public Gender Gender { get; set; }

    public DateTime DateOfBirth { get; set; }

    public UserType UserType { get; set; }

    public ICollection<Comment> Comments { get; set; }

    public ICollection<Dog> Dogs { get; set; }

    public ICollection<Appointment> Appointments { get; set; }

    // Audit info
    public DateTime CreatedOn { get; set; }

    public DateTime? ModifiedOn { get; set; }

    // Deletable entity
    public bool IsDeleted { get; set; }

    public DateTime? DeletedOn { get; set; }

    public virtual ICollection<IdentityUserRole<string>> Roles { get; set; }

    public virtual ICollection<IdentityUserClaim<string>> Claims { get; set; }

    public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }
}

Я хочу дважды сопоставить одного и того же пользователя приложения в классе назначений следующим образом:

public class Appointment : BaseDeletableModel<int>
{
    public bool IsHappening { get; set; }

    public int Timer { get; set; }

    public decimal TaxSoFar { get; set; }

    public DateTime Date { get; set; }

    public DateTime StartTime { get; set; }

    public DateTime EndTime { get; set; }

    public string OwnerId { get; set; }

    [ForeignKey("Id")]
    public virtual ApplicationUser Owner { get; set; }

    public string DogsitterId { get; set; }

    [ForeignKey("Id")]
    public virtual ApplicationUser Dogsitter { get; set; }
}

Я спрашиваю: Возможно ли это сделать таким образом или это логически неверно? Должен ли я создавать отдельные классы Dogsitter и Owner и, если да, как я могу связать их с ApplicationUsers (Как связать их обоих с ApplicationDbContext).

...