我有一个WebAPI OData v3接口使用ODataConventionModelBuilder
。它含有可继承了一些实体,并且还具有抽象对象的集合的模式:ODataConventionModelBuilder与继承实体
public abstract class BaseObject
{
[Key]
public int Id { get; set; }
[ForeignKey("Object3")]
public int? ParentId { get; set; }
public virtual Object3 Parent { get; set; }
}
public class Object1: BaseObject
{
}
public class Object2: BaseObject
{
}
public class Object3
{
[Key]
public int Id { get; set; }
public ICollection<BaseObject> MyObjects { get; set; }
}
我打电话使用微风与客户端的元数据接口,使用扩展:
http://example.com/api/Object3?$expand=MyObjects
服务器响应看起来是这样的:
{
"odata.type":"MyNamespace.Object1",
"odata.id":"http://example.com/api/BaseObject(1)",
"[email protected]":"http://example.com/api/BaseObject(1)/Parent",
"Id":1,
"ParentId":1
}
微风可识别该类型Object1的实体。但是,如果我修改实体并保存更改,则会将POST请求发送到http://example.com/api/BaseObject(1)
。为了能够处理不同的具体类型,我需要POST请求去特定的控制器http://example.com/api/Object(1)
。
我需要改变什么,以便Breeze使POST调用更新到具体控制器而不是基础对象的控制器?
更新:在检查Breeze源代码后,它看起来像Breeze使用odata.id作为POST请求的URI。是否有可能让OData API将具体对象的URI作为odata.id而不是基础对象返回?