Не удается получить данные из одата - PullRequest
0 голосов
/ 20 февраля 2019

Раньше odata работало нормально, но когда я изменил название модели на случай змеи со taContenants на TA_CONTENANTS (мне потребовались эти изменения, чтобы сопоставить правильные имена с нашими полями БД при первом подходе к базе данных EF)

Когда я добавляю эту строку

            //services.AddODataQueryFilter();

Ничего не работает вообще

Теперь я получаю эту ошибку на http://localhost:57746/api/odata/TA_CONTENANTS

Cannot GET /api/odata/TA_CONTENANTS

вот это config

namespace KmCore
{
    public class Startup
    {
        public Startup(IConfiguration configuration, IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
    .SetBasePath(env.ContentRootPath)
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
    .AddEnvironmentVariables().Build();

            configuration = builder;
            Configuration = configuration;
            StaticConfig = configuration;
            C_Interface_Meta.IntialiserBdd();
        }

        public IFileProvider FileProvider { get; }

        public static IConfiguration StaticConfig { get; private set; }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<DataContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("SI_KM")));
            services.AddDbContext<NSG_DBContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("NSG_DB")));

            //DEvexpress
            services.AddDevExpressControls(settings => settings.Resources = ResourcesType.ThirdParty | ResourcesType.DevExtreme);

            //Devextreme
            services
              .AddCors(options =>
              {
                  options.AddPolicy("AllowAnyOrigin", builder =>
                  {
                      builder.AllowAnyOrigin();
                  });
              });
            services
            .AddMvc()
            // ... other settings of the MVC service ...
            .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
            //services.AddMvc().AddWebApiConventions(); //Add WebApi
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidateAudience = true,
                    ValidateLifetime = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer = Configuration["Jwt:Issuer"],
                    ValidAudience = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            });
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddMvc().AddDefaultReportingControllers();
            services.ConfigureReportingServices(configurator =>
            {
                configurator.ConfigureReportDesigner(designerConfigurator =>
                {
                    designerConfigurator.RegisterDataSourceWizardConfigFileConnectionStringsProvider();
                });
            });

            services.AddOData();
            //services.AddODataQueryFilter();
            //services.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            DashboardConfigurator.PassCredentials = true;
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // In production, the Angular files will be served from this directory

            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            var reportDirectory = Path.Combine(env.ContentRootPath, "Reports");
            DevExpress.XtraReports.Web.Extensions.ReportStorageWebExtension.RegisterExtensionGlobal(
                new KmReportStorageWebExtension("DefaultConnection", reportDirectory));
            app.UseCors("AllowAnyOrigin");
            if (env.IsDevelopment())
            {
                //app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseDevExpressControls();

            app.UseAuthentication();
            app.UseMvc(b =>
            {
                b.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
                b.MapODataServiceRoute("odata", "api/odata", GetEdmModel(app.ApplicationServices));
            });
            app.UseMvc(routes =>
            {
                routes.MapDashboardRoute("api/dashboard");
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core, see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";
                spa.Options.StartupTimeout = new TimeSpan(0, 0, 360);
                //spa.UseAngularCliServer(npmScript: "start");
                //spa.UseProxyToSpaDevelopmentServer("http://localhost:58135/");
                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "debug");
                }
            });
        }

        private static IEdmModel GetEdmModel(IServiceProvider serviceProvider)
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder(serviceProvider);
            ODataConventionModelBuilder builder1 = new ODataConventionModelBuilder();
            builder.EntitySet<MO_UTILISATEURS>("MO_UTILISATEURS");
            builder.EntitySet<TA_CONTENANTS>("TA_CONTENANTS");
            builder.EntitySet<EE_MESURES>("EE_MESURES");
            builder.EntitySet<MO_UTILISATEURS_MENU>("MO_UTILISATEURS_MENU");
            builder.EntitySet<V_KM_MO_MENU>("V_KM_MO_MENU");
            return builder.GetEdmModel();
        }

    }
}

Может кто-нибудь помочь мне в этом?

...