public void Save(Project aggregateRoot) { Guard.ThrowIfNull(aggregateRoot, nameof(aggregateRoot)); var state = aggregateRoot.GetState(); var existing = _context.Projects.SingleOrDefault(p => p.ProjectId == state.ProjectId.Value); if (existing != null) { existing.UpdateFrom(state); } else { _context.Projects.Add(ProjectDao.CreateFrom(state)); } _context.SaveChanges(); }