Simple.OData.Client Inheritance Issue

465 Views Asked by At

I am currently having an issue when using Simple.OData.Client to retrieve an object.

Here's the call, using an instance of ODataClient

RecurringObjectView model = await client.For<RecurringObjectView>("RecurringObjects")
                                        .Key(id)
                                        .Expand(r => r.RecurrenceSetting)
                                        .FindEntryAsync();

I'm able to trace the data coming from the API, and all is well. Below is an extract of the Json being return by the server.

{
    "RecurrenceSetting": {
        "@odata.type":"#Namespace.Of.The.DailyRecurrenceSettingView",
        "Id":16
        // more settings...
     }
     // more values...
}

The issue is that the RecurrenceSetting object is abstract, and in turn is giving the following error...

Unable to create an instance of type RecurrenceSettingView that does not have a default constructor.

For reference purposes, here are extracts of the class definitions...

public class RecurringObjectView
{
    public int Id { get; set; }

    public virtual RecurrenceSettingView RecurrenceSetting { get; set; }

    // loads more properties...
}


public abstract class RecurrenceSettingView
{
    public int Id { get; set; }

    // common recurrence setting properties...
}

public class DailyRecurrenceSettingView :
    RecurrenceSettingView
{
    // daily specific settings...
}
0

There are 0 best solutions below