title: How to properly integrate OData with ASP.net Core
body: <p>I'm trying to create a new ASP.NET Core project with a "simple" web api using OData and EntityFramework. I have previously used OData with older versions of ASP.NET.</p>
  
  <p>I have set up a controller with only a simple get function. I've managed to get it working with basic OData commands as filter and top, but I can't get the expand command working. I think it's because I can't quite figure out how to set it up in Startup.cs. I have tried a lot of things including following some odata samples from Github:</p>
  
  <p><a href="https://github.com/OData/WebApi/tree/vNext/vNext/samples/ODataSample.Web" rel="nofollow noreferrer">https://github.com/OData/WebApi/tree/vNext/vNext/samples/ODataSample.Web</a>
  <a href="https://github.com/bigfont/WebApi/tree/master/vNext/samples/ODataSample.Web" rel="nofollow noreferrer">https://github.com/bigfont/WebApi/tree/master/vNext/samples/ODataSample.Web</a></p>
  
  <p>In my startup file I try to exclude some properties from the Service class which has no effect at all. So the problem may lie in the way I'm using the IDataService interface. (The ApplicationContext implements it like in the samples)</p>
  
  <p>To be clear I'm creating a ASP.NET Core web api with the full .NET Framework and not only .Core framework. My current code is a mix of the best/worst of both samples and work in the sense that I can filter the WebAPI but can't get it to expand or hide properties.</p>
  
  <p>Can anyone see what I'm missing og have a working ASP.NET Odata sample. I'm new to the whole setup in startup.cs? Guess I'm looking for someone who have made this work.</p>
  
  <p><strong>Controller</strong></p>
  
  
  
  <pre><code>[EnableQuery]
  [Route("odata/Services")]
  public class ServicesController : Controller
  {
      private IGenericRepository&lt;Service&gt; _serviceRepo;
      private IUnitOfWork _unitOfWork;
  
      public ServicesController(IGenericRepository&lt;Service&gt; serviceRepo, IUnitOfWork unitOfWork)
      {
          _serviceRepo = serviceRepo;
          _unitOfWork = unitOfWork;
      }
  
      [HttpGet]
      public IQueryable&lt;Service&gt; Get()
      {
          var services = _serviceRepo.AsQueryable();
          return services;
      }
  }
  </code></pre>
  
  <p><strong>startup</strong></p>
  
  
  
  <pre><code>using Core.DomainModel;
  using Core.DomainServices;
  using Infrastructure.DataAccess;
  using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Logging;
  using Microsoft.Extensions.Configuration;
  using Microsoft.AspNetCore.OData.Extensions;
  
  namespace Web
  {
  public class Startup
  {
      public Startup(IHostingEnvironment env)
      {
          var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
              .AddEnvironmentVariables();
  
          if (env.IsDevelopment())
          {
              // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
              builder.AddApplicationInsightsSettings(developerMode: true);
          }
          Configuration = builder.Build();
      }
  
      public IConfigurationRoot Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          // Add framework services.
          services.AddApplicationInsightsTelemetry(Configuration);
          services.AddMvc().AddWebApiConventions();
  
          services.AddSingleton&lt;ApplicationContext&gt;(_ =&gt; ApplicationContext.Create());
  
          services.AddSingleton&lt;IDataService, ApplicationContext&gt;();
  
          services.AddOData&lt;IDataService&gt;(builder =&gt;
          {
              //builder.EnableLowerCamelCase();
              var service = builder.EntitySet&lt;Service&gt;("Services");
              service.EntityType.RemoveProperty(x =&gt; x.CategoryId);
              service.EntityType.RemoveProperty(x =&gt; x.PreRequisiteses);
          });
  
  
          services.AddSingleton&lt;IGenericRepository&lt;Service&gt;, GenericRepository&lt;Service&gt;&gt;();
          services.AddSingleton&lt;IUnitOfWork, UnitOfWork&gt;();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          loggerFactory.AddConsole(Configuration.GetSection("Logging"));
          loggerFactory.AddDebug();
  
          //ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
  
          app.UseApplicationInsightsRequestTelemetry();
  
          //var builder = new ODataConventionModelBuilder(app.ApplicationServices.GetRequiredService&lt;AssembliesResolver&gt;());
          //var serviceCtrl = nameof(ServicesController).Replace("Controller", string.Empty);
          //var service = builder.EntitySet&lt;Service&gt;(serviceCtrl);
          //service.EntityType.RemoveProperty(x =&gt; x.CategoryId);
  
          app.UseOData("odata");
  
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
              app.UseBrowserLink();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
          }
  
          app.UseApplicationInsightsExceptionTelemetry();
  
          app.UseStaticFiles();
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
      }
  }
  </code></pre>
  
  <p><strong>Project.json dependencies</strong></p>
  
  
  
  <pre><code>  "dependencies": {
      "Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
      "Microsoft.AspNet.Identity.EntityFramework": "2.2.1",
      "Microsoft.AspNetCore.Diagnostics": "1.0.0",
      "Microsoft.AspNetCore.Identity": "1.0.0",
      "Microsoft.AspNetCore.Mvc": "1.0.1",
      "Microsoft.AspNetCore.Razor.Tools": {
        "version": "1.0.0-preview2-final",
        "type": "build"
      },
      "Microsoft.AspNetCore.Routing": "1.0.1",
      "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
      "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
      "Microsoft.AspNetCore.StaticFiles": "1.0.0",
      "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
      "Microsoft.Extensions.Configuration.Json": "1.0.0",
      "Microsoft.Extensions.Logging": "1.0.0",
      "Microsoft.Extensions.Logging.Console": "1.0.0",
      "Microsoft.Extensions.Logging.Debug": "1.0.0",
      "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
      "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
      "Microsoft.AspNetCore.OData": "1.0.0-rtm-00015",
      "dnx-clr-win-x86": "1.0.0-rc1-update2",
      "Microsoft.OData.Core": "7.0.0",
      "Microsoft.OData.Edm": "7.0.0",
      "Microsoft.Spatial": "7.0.0"
  }
  </code></pre>