AbpODataEntityController

AbpODataEntityController

本文介绍了如何将自定义函数添加到AbpODataEntityController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的帖子中,关于如何向AbpODataEntityController添加自定义函数的一些建议.我已经尝试过,但无法实现自己想要的.

In a recent post, there is some suggestion about how to add a custom function to an AbpODataEntityController. I have tried but I can't achieve what I want.

例如,在我的AbpODataEntityController中,有两种方法分别称为TestEchoTest.

For example, in my AbpODataEntityController, there are two methods called Test and EchoTest.

public class TownsController : AbpODataEntityController<Town>, ITransientDependency
{
    public TownsController(IRepository<Town> repository) : base(repository)
    {
    }

    // [HttpPost]
    public string Test()
    {
        return "inanc";
    }

    // [HttpPost]
    // [HttpGet]
    public IActionResult EchoTest([FromODataUri] string param)
    {
        return Ok(string.Format("The param was {0}", param));
    }
}

我的Startup.cs有:

And my Startup.cs has:

builder.EntityType<Town>().Collection
    .Function("Test")
    .Returns<string>();
    //.Parameter<string>("param");

builder.EntityType<Town>()//.Action("stringTest")
    .Function("EchoTest")
    .Returns<IActionResult>()
    .Parameter<string>("param");

简单功能Test是可以的.结果为:

The simple function Test is OK. It gives a result as:

但是带有名称为param的参数的函数不起作用.我收到404错误.

But the function with a parameter with name param doesn't work. I get 404 error.

我通过 http://localhost:21021/odata/towns/调用该方法EchoTest?param = foo .

我哪里出错了?我应该有一些接受参数的自定义函数.

Where did I go wrong? I should have some custom function that accepts parameters.

谢谢.

推荐答案

您丢失了.Collection:

builder.EntityType<Town>().Collection
    .Function("EchoTest")
    .Returns<IActionResult>()
    .Parameter<string>("param");

正确的URL: http://localhost:21021/odata/镇/Default.EchoTest(param='foo')

这篇关于如何将自定义函数添加到AbpODataEntityController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 13:04