public bool Save(IUpdateEntry entry) { var id = entry.GetCurrentValue <string>(_entityType.FindProperty(StoreKeyConvention.IdPropertyName)); switch (entry.EntityState) { case EntityState.Added: return(_cosmosClient.CreateDocument(_collectionId, CreateDocument(entry))); case EntityState.Modified: var jObjectProperty = _entityType.FindProperty(StoreKeyConvention.JObjectPropertyName); var document = jObjectProperty != null ? (JObject)entry.GetCurrentValue(jObjectProperty) : null; if (document != null) { UpdateDocument(document, entry); } else { document = CreateDocument(entry); // Set Discriminator Property for updates document[_entityType.CosmosSql().DiscriminatorProperty.Name] = JToken.FromObject(_entityType.CosmosSql().DiscriminatorValue); } return(_cosmosClient.ReplaceDocument(_collectionId, id, document)); case EntityState.Deleted: return(_cosmosClient.DeleteDocument(_collectionId, id)); } return(false); }
public bool Save(IUpdateEntry entry) { var id = entry.GetCurrentValue <string>(_entityType.FindProperty("id")); switch (entry.EntityState) { case EntityState.Added: return(_cosmosClient.CreateDocument(_collectionId, CreateDocument(entry))); case EntityState.Modified: var document = CreateDocument(entry); // Set Discriminator Property for updates document[_entityType.CosmosSql().DiscriminatorProperty.Name] = JToken.FromObject(_entityType.CosmosSql().DiscriminatorValue); return(_cosmosClient.ReplaceDocument(_collectionId, id, document)); case EntityState.Deleted: return(_cosmosClient.DeleteDocument(_collectionId, id)); } return(false); }