DataProtection.PersistKeysToDbContext fails when using Cosmos DB EF 9. Possible included here. #59717
Open
1 task done
Labels
area-dataprotection
Includes: DataProtection
Is there an existing issue for this?
Describe the bug
Cosmos DB Entity Framework for .Net 9 now requires all LINQ functions to be asynchronous. When attempting to use the synchronous method, it throws the following error:
'Microsoft.EntityFrameworkCore.Database.SyncNotSupported': Azure Cosmos DB does not support synchronous I/O. Make sure to use and correctly await only async methods when using Entity Framework Core to access Azure Cosmos DB.
For example, Entity.ToList() will fail while Entity.ToListAsync() will succeed.
I have found that the following code changes to
EntityFrameworkCoreXmlRepository
will solve the problem. Note where I check if DB is Cosmos, and there make async calls. Someone more cleaver than I can probably simplify this.Question, can all EF providers support asynchronous methods? If so, then maybe make this async for all and not worry if this is for Cosmos or not?
Expected Behavior
No response
Steps To Reproduce
Create an asp.net project, .Net 9, with a Cosmos DB database. Then add data protection using the DbContext. Here is example code that will cause the error:
Note: The
ApplicationDbContext
uses Cosmos DB.Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: