EF core cosmos Foreign key
Author: Mehdi Sheikh
Originally Sourced from: https://stackoverflow.com/questions/73246393/ef-core-cosmos-foreign-key
I am working with EF core and Azure Cosmos DB. I have a problem with the foreign keys. When I load an entity, the related classes are not being loaded. For example, I want to select a user with its roles. It's connected to Users, Tenants, and Roles containers. The data is loaded, but the relations are not loaded:
I tried different ways of one-one/one-many relations. The last config for the relations is:
var tenantUserModel = modelBuilder.Entity<TenantUser>();
tenantUserModel.ToContainer(nameof(TenantUsers))
.HasNoDiscriminator()
.HasPartitionKey(tu => tu.TenantId)
.HasKey(tu => new {tu.TenantId,tu.UserId,tu.RoleId});
tenantUserModel.HasOne(tu => tu.User).WithMany().HasForeignKey(tu=>tu.UserId);
But it doesn't load the relation.