Entity Framework Core

Learn to use Entity Framework Core to query Cosmos DB from C# with LINQ.

Introduction to Entity Framework Core

Entity Framework (EF) Core is an object-relational mapping (ORM) framework created by Microsoft. It lets us query different types of databases, mainly SQL, using C# Language-Integrated Query (LINQ). ORMs can be very convenient because we don’t need to think about the syntax of queries or typos, and they integrate well with the language.

Note: It is important to know how the code is converted to a query to prevent unwanted results or cost/performance issues.

Cosmos DB provider

EF Core can integrate with Cosmos DB thanks to a specific provider.

Let’s see an example of an ASP.NET Core API to store music playlists, Cosmify. First, we need to install the Microsoft.EntityFrameworkCore.Cosmos package.

Then, we can define our model:

Get hands-on with 1200+ tech skills courses.