Asp.net web api 在OData操作中返回HttpResponseMessage

Asp.net web api 在OData操作中返回HttpResponseMessage,asp.net-web-api,odata,Asp.net Web Api,Odata,我想返回一个匿名类型,为此我使用HttpResponseMessage,但结果是代码406不可接受。这是我的密码 在WebApiConfig中 modelBuilder.EntitySet<Groups>("Groups"); var getComplete = modelBuilder.Entity<Groups>().Collection.Action("GetComplete"); getComplete.Returns<HttpResponseMessage

我想返回一个匿名类型,为此我使用HttpResponseMessage,但结果是代码406不可接受。这是我的密码

在WebApiConfig中

modelBuilder.EntitySet<Groups>("Groups");
var getComplete = modelBuilder.Entity<Groups>().Collection.Action("GetComplete");
getComplete.Returns<HttpResponseMessage>();
使用httpget方法将ApicController作为基类运行良好,但使用odata操作中的EntitySetController则不行

有什么想法吗


谢谢。

OData操作无法返回匿名对象。操作返回的类型必须声明为服务EDM模型。

OData操作无法返回匿名对象。操作返回的类型必须声明为服务EDM模型。

那么,如何返回ApiControllerOData集合中的匿名对象集合是同构的和强类型的。因此,在V3协议中无法返回匿名对象。您不能声明一个类型并使用它来代替匿名类型吗?我不能,因为我需要可查询性。我想在iQueryEnable中使用$filter、$top等另一个需要改进的答案是如何返回匿名对象集合,如ApiControllerOData集合是同构的和强类型的。因此,在V3协议中无法返回匿名对象。您不能声明一个类型并使用它来代替匿名类型吗?我不能,因为我需要可查询性。我想在iqueryable中使用$filter、$top等另一个需要改进的答案
[HttpPost]
[Queryable]
public HttpResponseMessage GetComplete(ODataActionParameters parameters)
{
        return this.Request.CreateResponse(HttpStatusCode.OK,db.Groups.Select(c => new 
        {
            ID = c.ID,
            DocumentType= c.DocumentType,
            Name = c.Name ,               
            Debits = c.GroupMvtos.Sum(cm => cm.Debits) ?? 0,
            Credits = c.GroupMvtos.Sum(cm => cm.Credits) ?? 0
        }));            
}