public virtual void SaveChanges() { foreach (var item in _uow.Flush()) { var repository = GetRepository(item); if (repository == null) { throw new InvalidOperationException($"A repository for type {item} was not supplied"); } var mapper = repository.Mapper; var aggregate = item; var state = _state.Get(item); if (state.Status == EntityStatus.Deleted) { mapper.Delete(item, state); Publish(ProxyUtils.GetTargetEntityType(item), x => x.Delete(aggregate, this)); } else if (state.Status == EntityStatus.Dirty) { mapper.Update(item, state); Publish(ProxyUtils.GetTargetEntityType(item), x => x.Update(aggregate, this)); } else if (state.Status == EntityStatus.New) { mapper.Insert(item, state); Publish(ProxyUtils.GetTargetEntityType(item), x => x.Create(aggregate, this)); } state.Clean(); } Flushed(this, new GraphSessionFlushedEventArgs(this)); }
public EntityState Create(object proxy) { var item = ProxyUtils.GetTargetEntity(proxy); var state = new EntityState(ProxyUtils.GetEntityId(proxy)); _state.Add(item, state); return(state); }
private IRepository GetRepository(object item) { var type = ProxyUtils.GetTargetType(item); if (!_repositories.ContainsKey(type)) { _repositories[type] = _repositoryFactory.Create(this, type); } return(_repositories[type]); }
public bool Contains(object proxy) { var item = ProxyUtils.GetTargetEntity(proxy); if (item == null) { return(false); } return(_state.ContainsKey(item)); }
public object Get(string id, Type type) { return(_items.SingleOrDefault(x => ProxyUtils.GetTargetType(x) == type && _entityStateCache.Get(x).GetIdentifier().Equals(id))); }
public void Remove(object proxy) { var item = ProxyUtils.GetTargetEntity(proxy); _state.Remove(item); }
public EntityState Get(object proxy) { var item = ProxyUtils.GetTargetEntity(proxy); return(_state[item]); }