'Entity Framework Core 5 and CosmosDB SQL API - Include extension method does not work

I have followed the steps from the following EF Core 5 site in order to store and read items from the CosmosDB. Here is the site: https://www.learnentityframeworkcore5.com/database-providers/cosmos

Storing works as expected, but when running the command from the tutorial to read items, I'm getting following error:

System.InvalidOperationException: 'Including navigation 'Navigation: Author.Books (List) Collection ToDependent Book Inverse: Author' is not supported as the navigation is not embedded in same resource.'

The line of code which throws the exception:

var list = context.Authors
    .Include(a => a.Books)
    .ToList();

It seems that Include method is not supported in EF Core 5 for CosmosDB. Does anyone have some experience with this issue?



Solution 1:[1]

I would take a look at the Microsoft.EntityFrameworkCore.Cosmos instead.

As it provides a means to map the Authors to Books

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
       modelBuilder.Entity<Authors>()
                .HasMany(p => p.Books);
}

https://docs.microsoft.com/en-us/ef/core/providers/cosmos/planetary-docs-sample https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DenisJC