Currently I am working on legacy sytem db which is quite messy
In hotel booking system table we have Reservation table which has one to many relation with different reservation system(e.g hotel reservation, train reservation) based on systemid
Table - Reservation
Column Reservation_id (int) | System_id(int) | Customer_id|
45432 | can be 1,2,3 etc | 343 |
e.g. system id 1 can be hotel, 2 is train etc.
Table - [System]_Reservation system can be hotel or train or flight
Column Reservation_id (int) | create_date(datetime) |other columns
45432 |
Currently to load reservation details, we query the reservation table than based on system id we query respective reservation system table. each reservation can have 0..1* to many relationship with reservation system.
How can i create EF mdel builder around this.
I tried the following
[Table("Hotel_Reservation")]
public class HotelReservation
{
public int Reservation_id { get; set; }
public Virtual Reservation ReservationInfo { get; set; }
//other properties etc
}
[Table("Reservation")]
public class Reservation
{
public Reservation()
{
HotelReservations = new HashSet<HotelReservation>();
TrainReservations = new HashSet<TrainReservation>();
}
public int Reservation_id { get; set; }
public int SystemID { get; set; }
public virtual ICollection<HotelReservation> HotelReservations { get; set; }
public virtual ICollection<TrainReservation> TrainReservations { get; set; }
//other properties etc
}
//On model builder class contains
Builder.Entity<TrainReservation>()
.HasOptional(x => x.ReservationInfo)
.WithMany(x => x.TrainReservations )
.HasForeignKey(x => x.Reservation_id);
but on initialization thros following error Multiplicity conflicts with the referential constraint in Role .....Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.