【发布时间】:2020-06-01 15:37:18
【问题描述】:
我的代码 EmployeTraining 中有一个实体的长名称,它在 OData 中用作实体,并且与控制器具有相同的名称。
Startup.cs
app.UseMvc(routeBuilder=>
{
routeBuilder.Expand().Select().Count().OrderBy().Filter().MaxTop(null);
routeBuilder.MapODataServiceRoute("EmployeTraining", "odata/v1", EdmModelBuilder.GetEdmModelEmploye());
});
EdmModelBuilder.cs
public static IEdmModel GetEdmModelEmployes()
{
var builder = new ODataConventionModelBuilder();
builder.EntitySet<EmployeTraining>("EmployeTraining");
return builder.GetEdmModel();
}
EmployeTrainingControllers.cs
public class EmployeTrainingController : ODataController
{
internal IEmployeService ServiceEmploye { get; set; }
public EmployesController(IEmployeService serviceEmploye)
{
ServiceEmploye = serviceEmploye;
}
//// GET api/employes
[HttpGet]
[MyCustomQueryable()]
public IQueryable<EmployeTraining> Get()
{
return ServiceEmploye.GetListeEmployes();
}
}
要调用我的服务,它只能通过以下 URL:https://{server}/odata/v1/rh/employetraining
但我需要使用这个 https://{server}/odata/v1/rh/employe-training 请帮忙。
【问题讨论】:
-
我试过但没用
-
您是如何定义
[MyCustomQueryable()]的?另外,您的请求网址包含rh,但我看不到您为路由属性或路由模板定义的任何内容。
标签: asp.net-core odata