Skip to content

Configuring multiple routes each with their own Edm model throws an error #996

Closed
@darrenferne

Description

@darrenferne

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am attempting to configure multiple odata routes, each with its own model, this gives the following error on startup:

The given key 'Asp.Versioning.OData.EdmTypeKey' was not present in the dictionary.

Example:
`var builder = WebApplication.CreateBuilder(args);

        // Add services to the container.

        builder.Services.AddControllers();
        // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen();

        builder.Services
            .AddMvc()
            .AddOData();

        builder.Services
            .AddApiVersioning(options =>
            {
                options.DefaultApiVersion = ApiVersion.Default;
                options.AssumeDefaultVersionWhenUnspecified = true;
                options.ReportApiVersions = true;
            })
            .AddOData(options =>
            {
                **options.AddRouteComponents("lettersapi");
                options.AddRouteComponents("wordsapi");

                options.ModelBuilder.DefaultModelConfiguration = (builder, version, route) =>
                {
                    if (route == "lettersapi")
                    {
                        builder.EntitySet<LetterType>("Letter");
                        builder.EntityType<LetterType>()
                               .HasKey(e => e.Id);
                    }
                    else if (route == "wordsapi")
                    {
                        builder.EntitySet<WordType>("Word");
                        builder.EntityType<WordType>()
                               .HasKey(e => e.Id);
                    }
                };**
            })
            .AddODataApiExplorer(options =>
            {
                options.GroupNameFormat = "'v'VVV";
                options.SubstituteApiVersionInUrl = true;
            });

        var app = builder.Build();

        // Configure the HTTP request pipeline.
        if (app.Environment.IsDevelopment())
        {
            app.UseSwagger();
            app.UseSwaggerUI();
        }

        app.UseHttpsRedirection();

        app.UseAuthorization();

        app.MapControllers();

        app.Run();`

Full code attached in Steps to Reproduce

Expected Behavior

I should be able to configure multiple routes each having its own model without issue.

Steps To Reproduce

Asp.Versioning.Test.zip

Repo

Exceptions (if any)

No response

.NET Version

Net7

Anything else?

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions