Шаблон ODataRoute не работает в. Net Core - PullRequest
0 голосов
/ 13 июля 2020

Я использовал ODataRoute с шаблоном в. Net. Работал нормально. Сейчас я пытаюсь перейти на. Net Core, но это не работает. Мои ConfigureServices:

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddOData();
        services.AddRouting();
        services.AddMvc();
    }

Конфигурация:

public static void Configure(object appBuilder)
    {
        var app = appBuilder as IApplicationBuilder;
        var builder = new ODataConventionModelBuilder(app.ApplicationServices);
        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseAuthorization();
        app.UseODataBatching();
        var edmModel = GetEdmModel(builder);
        app.UseDeveloperExceptionPage();
        app.UseEndpoints(routeBuilder =>
        {
            routeBuilder.EnableDependencyInjection();
            routeBuilder.Select().Filter().Expand();
            routeBuilder.MapODataRoute("OData", "odata", b =>
            {
                b.AddService(Microsoft.OData.ServiceLifetime.Singleton, sp => edmModel);
                var customRoutingConvention = new ODataCustomRoutingConvention();
                var conventions = ODataRoutingConventions.CreateDefault();
                //Workaround for https://github.com/OData/WebApi/issues/1622
                conventions.Insert(0, new AttributeRoutingConvention("OData", app.ApplicationServices, new DefaultODataPathHandler()));
                //Custom Convention
                conventions.Insert(0, customRoutingConvention);
                b.AddService<IEnumerable<IODataRoutingConvention>>(Microsoft.OData.ServiceLifetime.Singleton, a => conventions);
            });
        });
    }

    static IEdmModel GetEdmModel(ODataConventionModelBuilder builder)
    {
        builder.EntityType<Student>().HasKey(a => a.Id);
        builder.EntitySet<Student>("Student");
        return builder.GetEdmModel();
    }

Контроллер:

 public class StudentController : BaseController<Student>
{
    [EnableQuery]
    [ODataRoute("Student(Id={key})")]
    public override IActionResult Get(string key)
    {
        return Get("Id", key);
    }
}

Он возвращает 404, когда я отправляю запрос https://localhost: 44383 / odata / Студент (Id = 'DBS') * Как это исправить?

...