I use CosmosDb with the Entity Framework. I need that when saving data if one of the properties is null
, it is stored as undefined
.
Is there any option to initialize DbContext
from CosmosClient
, or set CosmosSerializationOptions
?
I tried the following option, but it does not work for me:
context.Database.GetCosmosClient().ClientOptions.SerializerOptions = new CosmosSerializationOptions()
{
IgnoreNullValues = true
};
The option without using EF is working:
CosmosClient cosmosClient = new CosmosClientBuilder(EndpointUri, PrimaryKey)
.WithSerializerOptions(new CosmosSerializationOptions() { IgnoreNullValues = true })
.Build();
//The current result
{
"Id": "fad8b443-6d10-4009-853c-efb6aac18031",
"Discriminator": "User",
"FirstName": "Charley",
"LastName": null
}
//Expected result
{
"Id": "fad8b443-6d10-4009-853c-efb6aac18031",
"Discriminator": "User",
"FirstName": "Charley"
}