Asp.net odata v4产品({key})/GenerateVariants路由配置错误

Asp.net odata v4产品({key})/GenerateVariants路由配置错误,asp.net,asp.net-mvc,odata,asp.net-web-api2,odata-v4,Asp.net,Asp.net Mvc,Odata,Asp.net Web Api2,Odata V4,产品上有一个函数,它以列表的形式生成变体。目前它返回: The related entity set could not be found from the OData path 这是我的网站配置: builder.EntityType<Product>().Function("GenerateVariants").Returns<List<ProductVariant>>(); ////.Parameter<string>("save").Op

产品上有一个函数,它以列表的形式生成变体。目前它返回:

The related entity set could not be found from the OData path
这是我的网站配置:

builder.EntityType<Product>().Function("GenerateVariants").Returns<List<ProductVariant>>();
////.Parameter<string>("save").OptionalParameter = true;
builder.EntityType().Function(“GenerateVariants”).Returns();
////.参数(“保存”)。OptionalParameter=true;
这是我在ProductController上的方法

    //http://localhost:26696/odata/Products(b2a35842-7b68-e511-beda-6c71d92133bc)/GenerateVariants
    [HttpGet]
    [ODataRoute("Products({key})/GenerateVariants")]
    public async Task<IHttpActionResult> GenerateVariants([FromODataUri] Guid key) // bool save = false
    {
        var product = await db.Products.Include("option1").Include("option2").Include("option3").Where(el => el.Id == key).FirstOrDefaultAsync();
        List<ProductVariant> productVariants = product.GenerateProductVariants();
        //if (save)
        //{
        //    db.ProductVariants.AddRange(productVariants);
        //    await db.SaveChangesAsync();
        //}
        return Ok(productVariants);
    }
//http://localhost:26696/odata/Products(b2a35842-7b68-e511-beda-6c71d92133bc)/发电商
[HttpGet]
[ODataRoute(“产品({key})/GenerateVariants”)]
公共异步任务生成器变量([FromODataUri]Guid键)//bool save=false
{
var product=await db.Products.Include(“option1”).Include(“option2”).Include(“option3”).Where(el=>el.Id==key.FirstOrDefaultAsync();
List productVariants=product.GenerateProductVariants();
//如果(保存)
//{
//db.ProductVariants.AddRange(ProductVariants);
//等待db.saveChangesSync();
//}
返回Ok(产品变量);
}
实际上,我希望我的productController生成一个ProductVariant列表。但我目前的错误是:

{
  "error":{
    "code":"","message":"An error has occurred.","innererror":{
      "message":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata.metadata=minimal'.","type":"System.InvalidOperationException","stacktrace":"","internalexception":{
    "message":"The related entity set could not be found from the OData path. The related entity set is required to serialize the payload.","type":"System.Runtime.Serialization.SerializationException","stacktrace":"   bij System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)\r\n   bij System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n   bij System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---\r\n   bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   bij System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n   bij System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()"
      }
    }
  }
}
{
“错误”:{
“代码”:”“消息”:“发生错误”。、“内部错误”:{
“消息”:“ObjectContent`1”类型未能序列化内容类型“application/json;odata.metadata=minimal.”的响应正文,“类型”:“System.InvalidOperationException”,“stacktrace”:“internalexception”:{
“消息”:“无法从OData路径找到相关实体集。序列化负载需要相关实体集。”,“类型”:“System.Runtime.Serialization.SerializationException”,“stacktrace”:“bij System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject”(对象图,类型,ODataMessageWriter messageWriter,ODataSerializerContext writeContext)\r\n bij System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(类型,对象值,流writeStream,HttpContent内容,HttpContentHeaders)\r\n bij System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(类型类型、对象值、流writeStream、HttpContent内容、TransportContext TransportContext、CancellationToken CancellationToken)\r\n---Einde van STACKTRACEING vanaf vorige locatie waar UITZONDER是opgetreden---\r\n bij System.Runtime.CompilerServices.TaskAuiter.ThrowForNonSuccess(Task Task Task)\r\n bij System.Runtime.CompilerServices.TaskAuiter.HandleNonSuccessAndDebuggerNotification(Task Task Task Task Task)\r\n bij System.Runtime.CompilerServices.TaskAuiter.GetResult()\r\n bij System.Web.Http.WebHost.HttpControllerHandler.d_u1b.MoveNext()
}
}
}
}
我有点想知道应该调整什么以使其工作。

出于某种原因(我想我已经全部尝试过了),以下更改在ProductVariantController中是正确的(最初是在ProductsController中)

我最后的改变是:

            builder.EntityType<ProductVariant>()
            .Function("GenerateFromProduct")
            .ReturnsCollectionFromEntitySet<ProductVariant>("ProductVariants");
builder.EntityType()
.函数(“GenerateFromProduct”)
.ReturnsCollectionFromEntitySet(“产品变量”);
包括迁移路由(在webapiconfig中)和ProductVariantController上