title: ASP.Net Core 2.0 API OData without Entity Framework but stored procedures
body: <p>Quite new to ASP.Net Core, and specially with API's.
  In the past I was used to create simple api's using the default controller like: </p>
  
  <pre><code>    [Produces("application/json")]
      [Route("api/TestCust")]
      public class TestCustController : Controller
      {
          // GET: api/TestCust
          [HttpGet]
          public IEnumerable&lt;Customer&gt; Get()
          {
              IEnumerable&lt;Customer&gt; customer = null;
              .... 
              return customer;
          }
  
  
  
    // GET: api/TestCust/5
          [HttpGet("{id}", Name = "Get")]
          public IEnumerable&lt;Customer&gt; Get(int id)
          {
              IEnumerable&lt;Customer&gt; customer = null;
              return customer;
          }
  </code></pre>
  
  <p>Now I am currently running into a new challenge as I am making an API but the client-side is already made by a third party. Which means, that I am forced to do it <em>their</em> way.</p>
  
  <p>Luckily it is well documented, and they provide samples of the request they will be sending to my API. One of those request is as follow: <code>/Customers?$filter=ID+eq+guid'1D225D75-A587-4AE4-BA9A-2224B2484EA5'</code> and in order to get all customers:  <code>/Customers?$orderby=Code&amp;$skip=100</code> </p>
  
  <p>Now, I am totally brand new to OData, I just found out about those yesterday and I have been following some tutorials about it. Although, most of them are using the Entity Framework, while I am using Dapper in combination with Stored Procedures. </p>
  
  <p>Tutorials followed: <a href="https://damienbod.com/2018/10/12/odata-with-asp-net-core/" rel="noreferrer">https://damienbod.com/2018/10/12/odata-with-asp-net-core/</a>, <a href="https://dotnetthoughts.net/perform-crud-operations-using-odata-in-aspnet-core/" rel="noreferrer">https://dotnetthoughts.net/perform-crud-operations-using-odata-in-aspnet-core/</a></p>
  
  <p>So I've been trying to make a request using         <code>[EnableQuery]</code>
  but that didn't work out just yet.
  I will link the error at the bottom.</p>
  
  <p>So, what is it that I've done exactly? Well I <strong>changed</strong> the <strong>Startup.cs</strong></p>
  
  <pre><code>  public void ConfigureServices(IServiceCollection services)
          {
              ...
              services.AddOData();
              services.AddODataQueryFilter()
              services.AddMvc();
              services.AddOptions();
          }
  </code></pre>
  
  <p>And inside my customer controller:</p>
  
  <pre><code> public class CustomersController : ODataController{   
      ...
  
  [EnableQuery]
          public IEnumerable&lt;Customer&gt; Get()
          {
              IEnumerable&lt;Customer&gt; allCustomers = null;
              IEnumerable&lt;Addresses&gt; allAddresses = null;
              IEnumerable&lt;Contacts&gt; allContacts = null;
  
              //Execute the procedures to fetch our objects.
              using (var connection = new SqlConnection(config.Value.ConnectionString.ToString()))
              {
                  allCustomers = connection.Query&lt;Customer&gt;("someproc");
                  allAddresses = connection.Query&lt;Addresses&gt;("someproc");
                  allContacts = connection.Query&lt;Contacts&gt;("someproc");
              }
              //Loop through our customer object
              foreach(var item in allCustomers)
              {
                  //Initialize a collection of address + contact
                  ICollection&lt;Contacts&gt; CustomerContact = null;
                  ICollection&lt;Addresses&gt; CustomerAddress = null;
  
                  //Bind the Contact and Address to the correct Customer using the CustomerID 
                  //Tijdelijk uitgezet omdat customer nu even geen GUID is..
  
                  //CustomerContact = allContacts.Where(x =&gt; x.Customer == item.Id).ToList();
                  //CustomerAddress = allAddresses.Where(x =&gt; x.Customer == item.Id).ToList();
                  item.Contacts = CustomerContact;
                  item.Addresses = CustomerAddress;
              }
              return allCustomers;
  }
  </code></pre>
  
  <p>And here is the message it returns in the browser/postman as 'error 400 bad request':</p>
  
  <blockquote>
    <p>The query specified in the URI is not valid. Cannot find the services container for the non-OData route. This can occur when using OData components on the non-OData route and is usually a configuration issue. Call EnableDependencyInjection() to enable OData components on non-OData routes. This may also occur when a request was mistakenly handled by the ASP.NET Core routing layer instead of the OData routing layer, for instance the URL does not include the OData route prefix configured via a call to MapODataServiceRoute()</p>
  </blockquote>
  
  <p>Full message - <a href="https://pastebin.com/QtyuaQv1" rel="noreferrer">https://pastebin.com/QtyuaQv1</a></p>