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

Start free today

Using Entity Framework Core with Azure SQL DB and Azure Cosmos DB

Play Using Entity Framework Core with Azure SQL DB and Azure Cosmos DB

The Discussion

  • User profile image
    ErikEJ
    You may find my blog post useful: Tips for making the most of EF Core with Azure SQL Database

    https://erikej.github.io/efcore/sqldb/2020/09/21/efcore-azure-sql-db.html
  • User profile image
    damen
    Is it recommended to use EF core with cosmosDB?
    The saved document appears to store the document in a "normalized" way.

    How does this impacts the query performance on cosmosDb, say I have a system that has lots of normalized tables?
  • User profile image
    Jeremy​Likness
    @damen:

    "Recommended" depends on your use case. The SDK is great; the most common use case is for teams already familiar with EF Core who want to take advantage of the conventions and API offered there.

    To be fair, I contrived the example to show discriminators but in the "real world" the posts would be an "owned entity" of the blog and get stored as embedded values rather than separate documents. That is possible, just not the scenario that I showed.
  • User profile image
    MisterMatt
    @JeremyLikness I have created a very similar simple DbContext and the save is working, storing the data with differentiator, and adding the foreign key. When I query the data the relational collection "Posts" is always empty. I tried forcing with Include, but that throws an operation exception. Any guidance for how to get the related items with differentiators to be returned?

    Edit: Accidentally made the original post with the wrong email address so logged in to repost.
  • User profile image
    Jeremy​Likness
    @MisterMatt the recommended way to do it is actually to have Posts just be owned by Blog. Then it will load without having to include. I wanted to show type discriminators in the example but should have clarified it's not a best practice to model relationships like that for Cosmos DB.

Add Your 2 Cents