I'm trying to use OData and I'm having a problem with using the $expand function.
I have 3 entities: Event, Order, Ticket
They are setup like this: Event:
public int Id { get; set; }
public string UserId { get; set; }
public string Name { get; set; }
public string ShopName { get; set; }
public string ImageUrl { get; set; }
public string Description { get; set; }
public DateTimeOffset Start { get; set; }
public DateTimeOffset End { get; set; }
public virtual ICollection<Order> Orders { get; set; } = new Collection<Order>();
Order:
public int Id { get; set; }
[ForeignKey("Event")]
public int EventId { get; set; }
public string CustomerFirstName { get; set; }
public string CustomerLastName { get; set; }
public string CustomerEmail { get; set; }
public string CustomerPhoneNumber { get; set; }
public string CustomerAddress { get; set; }
public string CustomerHouseNumber { get; set; }
public string TransactionId { get; set; }
public TransactionStatus Status { get; set; }
public DateTimeOffset OrderedOn { get; set; }
public virtual Event Event { get; set; }
public virtual ICollection<Ticket> Tickets { get; set; } = new Collection<Ticket>();
Ticket:
public int Id { get; set; }
[ForeignKey("Order")]
public int OrderId { get; set; }
public string Barcode { get; set; }
public virtual Order Order { get; set; }
If I want to retrieve an Event and expand Orders and then also expand Tickets, there's no issue. As long as I use Event as a starting point.
However, if I select an Order (which is working fine) and want to expand Tickets, I get the following error: "'DbQuery`1' cannot be serialized using the ODataMediaTypeFormatter."
Again, this ONLY happens if I want to retrieve the Tickets for a specific Order. If I select the Event and expand from there, everything is working fine.
Does anyone know what I'm doing wrong? I can't seem to figure it out.
Aucun commentaire:
Enregistrer un commentaire