1

Our project is a .NET Core Web API with a RavenDB backend and an angular 4 frontend.

In the Web API, I have a model as follows

public abstract class Offer
{
    public int MerchantId { get; set; }
    ...
}

public class BasicOffer : Offer
{
    public int OfferId { get; set; }
    public string Description { get; set; }
}

public class StandardOffer : BasicOffer
{
    public string ImageUrl { get; set; }
}


public class Section
{
    ...
    public ICollection<Offer> offers { get; set; }
}

public class Hub
{
    ...
    public ICollection<Section> sections { get; set; }
}

In our Angular app, we have the exact same models.

When try to update data using a POST request, the data sent by the Angular app contains the extra properties in the derived BasicOffer class, but when that data arrives at the Web API it only contains the properties in the base Offer class.

When I say "arrives", I mean putting a breakpoint on the first line of the POST request on the controller and looking at the parameters passed in.

Basically, how do I store data from a derived abstract class?

Thanks

lewtur
  • 603
  • 1
  • 6
  • 16
  • 1
    Possible duplicate of [JSON.NET Abstract / Derived Class Deserialization with WebAPI 2](https://stackoverflow.com/questions/20408771/json-net-abstract-derived-class-deserialization-with-webapi-2) – Judah Gabriel Himango Jun 15 '17 at 14:57
  • I don't believe this has anything to do with RavenDB; this is a behavior issue with the Web API model serialization. The link above shows some workarounds. – Judah Gabriel Himango Jun 15 '17 at 14:58

0 Answers0