Cosmin
Cosmin

Reputation: 41

EF Core 7 - Map a table in 2 lists

public class Customer
{
    public List<Appointment>? Appointments { get; set; }
    public List<Appointment>? History { get; set; }
}
    public class Appointment
    {
        public DateTimeOffset Date { get; set; }
        public Customer Customer { get; set; }
    }
        

I have those 2 classes, and my question is: how can I manually configure the relationship in the OnModelCreating, based on the date? My desire would be to have a table of customers which they can have multiple raws in the appointment table, from the DB point of view; from the entity point of view, I want customer.Appointments to contain appointments in the future and in the customer.History appointments from the past, based on the Date from the Appointment. (Basically I don't want to have only one list and filter each time based on a date and somehow I need to tell EF on migration that I'm talking about only one table even if I have 2 lists)

If I don't map them at all I get: "Unable to determine the relationship represented by navigation 'Appointment.Customer' of type 'Customer'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'."

Upvotes: 0

Views: 76

Answers (0)

Related Questions