Open Robelind opened 3 years ago
@Robelind I am a little bit confusing.
Since you said it's non-Edm, but you create the Edm model.
Since you have the Edm model created, do you config it in the startup.cs?
Please take a look the samples in sample folder.
Yes, I config it in startup.cs, as displayed under the header EDM model. I do not say it's non-Edm. It's ASP.Net that says the request doesn't have an associated EDM model. Please read again.
@Robelind How can you route to IActionResult Test()
, since it cannot meet conventional routing and I don't see 'attribute routing template` on the action.
Can you share with me your repo or repro?
I got this error message when I switched from "endpoint routing" (whatever that means) to "UseMvc" (whatever that means).
i.e. OData is set up like this
mvc.AddOData(opt => opt.AddRouteComponents("odata", OurDataModel.Get())
.Select().Filter().OrderBy().Count().Expand().SkipToken());
and then I commented out this in Startup.cs...
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "api/{apiVersion}/{controller}/{action=Index}/{id?}");
});
and introduced this...
// in ConfigureServices
IMvcBuilder mvc = services.AddControllers(options => {
options.EnableEndpointRouting = false; // this line is new
});
// in Configure()
app.UseMvc(routeBuilder => { });
After that, regular controllers kept working, but OData broke; /odata/$metadata says "The request must have an associated EDM model. Consider registering Edm model calling AddOData()."
@qwertie let's forget UseMvc?
Any update on this @qwertie . I am still facing the same issue
@qwertie / @Robelind / @surajrautela a suggestion to all of you is to always double check your endpoints are actively being detected as OData endpoints using the route debug view with $odata
. Please check the readme for more information on that debug endpoint.
If they are not being detected as OData, you are either not properly using expected conventions, or you are using non-matching attribute-based routes.
Sorry @surajrautela, I don't understand this stuff, I'm simply not using UseMvc
although I have a call to IServiceCollection.AddMvcCore
. My Configure
looks like this (but I don't need to serve pages, only APIs):
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) {
app.UseResponseCompression();
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseOpenApi();
app.UseSwaggerUi3();
}
app.UseCors();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => {
// Unknown purpose. Without this, all controllers report 404
endpoints.MapControllerRoute(name: "default", pattern: "api/{apiVersion}/{controller}/{action=Index}/{id?}");
});
}
Microsoft.AspNetCore.OData 8.0.3
EDM model
Controller
Request
Result
What am I doing wrong here?