I have the following classes:
public partial class ReservationVersion
{
public ReservationVersion()
{
this.Reservations = new HashSet<Reservation>();
this.ReservationItems = new HashSet<ReservationItem>();
}
public int ReservationVersionID { get; set; }
public Nullable<int> ReservationID { get; set; }
public string GUID { get; set; }
public string StartDate { get; set; }
public string StartTime { get; set; }
public string Duration { get; set; }
public virtual ICollection<Reservation> Reservations { get; set; }
public virtual Reservation Reservation { get; set; }
public virtual ICollection<ReservationItem> ReservationItems { get; set; }
}
public abstract partial class ReservationItem
{
public ReservationItem()
{
}
public int ReservationItemID { get; set; }
public Nullable<int> ReservationVersionID { get; set; }
public string GUID { get; set; }
public Nullable<int> ParentID { get; set; }
public Nullable<bool> NeedsConfirmation { get; set; }
public string ReservationSummary { get; set; }
public string Comment { get; set; }
public Nullable<int> ObjectStateID { get; set; }
public string StartDate { get; set; }
public string StartTime { get; set; }
public string Duration { get; set; }
public virtual ReservationVersion ReservationVersion { get; set; }
}
public abstract partial class Appointment : ReservationItem
{
public Appointment()
{
}
public string AppointmentDescription { get; set; }
}
public partial class AppointedActivity : Appointment
{
public Nullable<int> AppointedActivityID { get; set; }
public virtual Activity Activity { get; set; }
}
public partial class AppointedDevice : Appointment
{
public Nullable<int> AppointedDeviceID { get; set; }
public virtual Device Device { get; set; }
}
I'm using Entity Framework and I'm having trouble understanding why I can't correctly parse a complex object from a JSON post.
Here's the JSON being sent (which is a valid ReservationVersion
):
{
"ObjectStateID": 1,
"StartDate": "2017-10-31",
//Other props
"ReservationItems": [
{
"ReservationSummary": "Act",
"AppointedActivityID": 95874,
"AppointmentDescription": "ACT"
},
{
"ReservationSummary": "Device",
"AppointedDeviceID": 99040,
"AppointmentDescription": "DEV"
}
]
}
I can correctly read the ReservationVersion
but the collection of ReservationItems
is empty every time.
My guess is that there's a problem with ReservationItems
being an abstract class and the items I'm sending should correspond to AppointedSomething
, which inherits from Appointment
, which inherits from ReservationItems
Any help would be much appreciated