Problem:
I am working on a .NET Core 5.0 web app that is using Cosmos DB as my persistence store and it does not seem to be persisting enums when they are set to 0 (default value). In the code below, when I create a session, the default SessionStatus value is Planned. If I set the Session to InProgress or Completed. It shows up in the database with a value of 1 or 2 respectively.
My Code
Session Class
public class Session
{
[JsonProperty("creator_id")]
public string CreatorId { get; private set; }
[JsonProperty("session_status")]
public SessionStatus SessionStatus { get; private set; }
}
public enum SessionStatus
{
Planned,
InProgress,
Completed
}
Repo:
var document = await cosmosDbClient.CreateDocumentAsync(session);
CosmosClient:
public async Task<Document> CreateDocumentAsync(object document, RequestOptions options = null,
bool disableAutomaticIdGeneration = false, CancellationToken cancellationToken = default(CancellationToken))
{
return await _documentClient.CreateDocumentAsync(
UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName), document, options,
disableAutomaticIdGeneration, cancellationToken);
}
What I have tried:
- I have tried setting enum json converted on the Enum object to store as a string in db, but same behavior for session_status in db.
- I could set the default value for SessionStatus to 1 as a work around, but would rather understand the underyling issue.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…