/// <summary> /// Get raw value from entity document. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="fieldName"></param> /// <returns></returns> public T GetDocumentFieldForEntity <T>(object entity, string fieldName) { string id = IdentityMap.GetIdByEntity(entity); JToken documentField = DocumentManager.DocInfo(id).Document[fieldName]; T value = (T)Serializer.ResolveValue(documentField, typeof(T)); return(value); }
public void Delete(object entity) { string id = IdentityMap.GetIdByEntity(entity); if (null == id) { // Entity was not found in the identity map throw new Exception("Entity was not found"); } else { // Exist entity, mark as deleted. DocumentManager.MarkDeleted(id); } }
/// <summary> /// Mark an entity as updated. /// </summary> /// <param name="entity"></param> public void Update(object entity) { if (entity == null) { throw new ArgumentNullException("entity"); } EnsureEntityTypeMapped(entity.GetType()); string id = IdentityMap.GetIdByEntity(entity); if (null == id) { // New entity DocumentManager.MarkInserted(GetEntityInstanceId(entity)); IdentityMap.AddNewEntity(entity); } else { // Update managed entity. DocumentManager.MarkUpdated(id); IdentityMap.UpdateEntity(id, entity); } }