OData控制器不返回派生对象

时间:2017-04-21 16:24:52

标签: c# json asp.net-web-api odata xml-deserialization

我有这些课程

public class Control
{
public int ukey {get; set;}
public string ControlName {get; set;}
public string ControlType {get; set;}
public string Property {get; set;}
}

[DataContract]
[Serializable]
public class DeserializedProperty: Control
{
[DataMember]
public object DeserializedProp {get; set;}
}

Control类中,成员Property是一个XML字符串。基于控件类型,每个控件的XML都不同。

我想查询数据库,获取所有控件,将属性反序列化为对象并返回它。这就是我的GET方法的样子:

public class OData_ControlsController : ODataController
{
[Queryable]
public HttpResponseMessage Get([FromODataUri] int id)
{
List<DeserializedProperty> deserializedSteps = new List<DeserializedProperty>();

var controls = getAllControls(id);//returns all control
foreach(var control in controls)
{
     DeserializedProperty prop = new DeserializedProperty();
     prop.DeserializedProp = _deserialize(control.Property);
     deserializedSteps.Add(prop);
}

return Request.CreateResponse(HttpStatusCode.OK, deserializedSteps);
}
}

_deserialize方法正确地反序列化XML。在return行上,deserializedSteps具有基类(Control)和派生类(DeserializedProperty),但是当我在客户端获得响应时,它不会#39}。在JSON中有DeserializedProp个对象。响应只有基类属性。

如何退回DeserializedProperty (Control + DeserializedProp)

0 个答案:

没有答案
相关问题