I'm using entity framework core. I want to have 3 tables: Appoitments, Users and Roles. The 'Users' table contains application members with different roles. Is there a way to have 'Appoitments' table with foreign keys: ClientID and ConsultantID of type 'User'?
public class ApplicationUser : IdentityUser
{
public List<Appointment> Appointments { get; set; }
}
public class Appointment
{
public int AppointmentId {get;set;}
public DateTime Date { get; set; }
public int RoomNumber { get; set; }
public ApplicationUser ConsultantId { get; set; }
public ApplicationUser ClientId { get; set; }
}
I created classes ApplicationUser and Appointment and in ApplicationDbContext i added property: public DbSet Appointments { get; set; }.
But when I tried to add migration, Packet Manager threw "(Unable to determine the relationship represented by navigation property 'ApplicationUser.Appointments' of type 'List'.
Not enough information in the question to really distinguish what is going on.. but I don't see why something like this wouldn't work:
public class Appointment
{
public int AppointmentId {get;set;}
public DateTime Date { get; set; }
public int RoomNumber { get; set; }
[ForeignKey("Consultant")]
public int ConsultantId { get; set; }
[ForeignKey("Client")]
public int ClientId { get; set; }
public ApplicationUser Consultant { get; set; }
public ApplicationUser Client { get; set; }
}