我正在尝试使用OData和EntityFramework创建一个带有"简单"web api的新ASP.NET Core项目.我之前使用OData与旧版本的ASP.NET.
我已经设置了一个只有一个简单的get函数的控制器.我已经设法使用基本的OData命令作为过滤器和顶部,但我无法使扩展命令工作.我想这是因为我无法弄清楚如何在Startup.cs中设置它.我尝试过很多东西,包括跟随Github的一些odata样本:
https://github.com/OData/WebApi/tree/vNext/vNext/samples/ODataSample.Web https://github.com/bigfont/WebApi/tree/master/vNext/samples/ODataSample.Web
在我的启动文件中,我尝试从Service类中排除一些根本没有效果的属性.所以问题可能在于我使用IDataService接口的方式.(ApplicationContext像样本一样实现它)
要明确我正在使用完整的.NET Framework创建一个ASP.NET Core web api,而不仅仅是.Core框架.我当前的代码是两个样本中最好/最差的混合,并且我可以过滤WebAPI,但不能让它扩展或隐藏属性.
任何人都可以看到我缺少的东西og有一个工作的ASP.NET Odata样本.我是startup.cs中整个设置的新手?猜猜我正在找一个做过这项工作的人.
调节器
[EnableQuery]
[Route("odata/Services")]
public class ServicesController : Controller
{
private IGenericRepository<Service> _serviceRepo;
private IUnitOfWork _unitOfWork;
public ServicesController(IGenericRepository<Service> serviceRepo, IUnitOfWork unitOfWork)
{
_serviceRepo = serviceRepo;
_unitOfWork = unitOfWork;
}
[HttpGet]
public IQueryable<Service> Get()
{
var services = _serviceRepo.AsQueryable();
return services;
}
}
Run Code Online (Sandbox Code Playgroud)
启动
using Core.DomainModel;
using Core.DomainServices;
using Infrastructure.DataAccess;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.OData.Extensions;
namespace Web
{
public class Startup …Run Code Online (Sandbox Code Playgroud) c# odata asp.net-web-api-odata asp.net-core asp.net-core-webapi