Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.

Start free today

Getting started with OData and Cosmos DB in ASP.NET Core

Play Getting started with OData and Cosmos DB in ASP.NET Core

The Discussion

  • User profile image
    SDV
    This, and the accompanying blog posts, are great but what about if I can't go directly to the repository layer from the controller?

    Layered architecture is such a common pattern (that helps isolate your public API from changes to the database) that it would be great to see an example of how to use odata with a service layer in between the controller and repository.

    It is far from clear to me how to go about this.

    Also, what about if we're using the Cosmos SDK rather than Entity Framework?

    Thanks.
  • User profile image
    hassanhabib
    @SDV: If your services layer is returning an IQueryable or IEnumerable you're good to go, you don't have to have direct access to your DbContext or Repository.
  • User profile image
    Gilles

    The sample code performs a query to the backend cosmosdb store retrieving all todo items then does filter the data using odata in the web tier...well if the filtering cannot be done in the backend technology, it is going to be sub optimal not only from a pure performance aspect but also from a throughput aspect where more RUs will be consumed...
    Again if i want to query todos where name is XYZ, i do not want to retrieve all the non completed items from cosmosdb, then filter a massive list in the web tier...

  • User profile image
    Santiago

    @hassanhabib, is that the case? is filtering happening in the web tier?

  • User profile image
    Kinnett

    @Santiago @hassanhabib, this is the case, you could never use this in production environment with a container with any signification number of records. Is there a better more performant way of doing this?

  • User profile image
    Brian

    This doesn't show OData working with Cosmos. It shows a Web API pulling the entire Cosmos collection into memory, and then letting OData work on the result set in memory. The Repository pattern hides this from the controller, but that's why the Repository first builds the List<T>.

Add Your 2 Cents