Я использую Odata с .NET Core.
и файл My Startup.cs, как указано выше
public void ConfigureServices(IServiceCollection services)
{
......
services.AddOData();
services.AddODataQueryFilter();
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
..............
app.UseMvc(b =>
{
b.MapRoute("default", "api/{controller}/{action}");
b.MapRoute("defaultApi", "api/{controller}/{id}");
b.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
b.MapODataServiceRoute("odata", null, GetEdmModel());
});
}
private static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.Namespace = "WebAPI";
builder.ContainerName = "DefaultContainer";
builder.EnableLowerCamelCase();
builder.EntitySet<User>("User");
builder.EntityType<User>()
.Filter(Microsoft.AspNet.OData.Query.QueryOptionSetting.Allowed);
builder.EntitySet<Camera>("Camera");
builder.EntityType<Camera>()
.Filter(Microsoft.AspNet.OData.Query.QueryOptionSetting.Allowed);
return builder.GetEdmModel();
}
Я хочу использовать odata с динамическими моделями, которые являются классами моделей баз данных. При создании новой таблицы базы данных я должен создать строитель builder.EntitySet<Camera>("Camera");