使用Simple.OData.Client检索对象时,我目前遇到了问题。
此处使用ODataClient
RecurringObjectView model = await client.For<RecurringObjectView>("RecurringObjects")
.Key(id)
.Expand(r => r.RecurrenceSetting)
.FindEntryAsync();
我能够跟踪来自API的数据,一切都很顺利。下面是服务器返回的Json的摘录。
{
"RecurrenceSetting": {
"@odata.type":"#Namespace.Of.The.DailyRecurrenceSettingView",
"Id":16
// more settings...
}
// more values...
}
问题是RecurrenceSetting
对象是抽象的,反过来又会出现以下错误......
无法创建类型为
RecurrenceSettingView
的实例 没有默认构造函数。
供参考,以下是类定义的摘录......
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...
}