[Route("")] [HttpPost] public IHttpActionResult CreateSChannels(EditSChannelsViewModel sChannelsViewModel) { SChannels sChannels = AutoMapper.Mapper.Map<EditSChannelsViewModel, SChannels>(sChannelsViewModel); _sChannelsAdapter.Add(sChannels); sChannelsViewModel = AutoMapper.Mapper.Map<SChannels, EditSChannelsViewModel>(sChannels); return Ok(sChannelsViewModel); } [Route("")] [HttpPut] public IHttpActionResult UpdateSChannels(EditSChannelsViewModel sChannelsViewModel) { SChannels sChannels = AutoMapper.Mapper.Map<EditSChannelsViewModel, SChannels>(sChannelsViewModel); _sChannelsAdapter.Update(sChannels); sChannelsViewModel = AutoMapper.Mapper.Map<SChannels, EditSChannelsViewModel>(sChannels); return Ok(sChannelsViewModel); }where Add or Update methods eventually lead to our generic RepositoryBase Add / Update methods:
public virtual void Add(T entity) { EntityState entityState = _siriusContext.GetEntityState(entity); if (entityState != EntityState.Detached) { _siriusContext.SetAdd(entity); } else { _dbSet.Add(entity); } try { SaveChanges(); } catch (DbUpdateException ex) { _exceptionParser.ThrowUniqueConstraintException(ex); } } public virtual void Update(T entity) { try { EntityState entityState = _siriusContext.GetEntityState(entity); if (entityState == EntityState.Detached) { _dbSet.Attach(entity); _siriusContext.SetModified(entity); } SaveChanges(); } //catch (DbEntityValidationException dbex) //{ // var msg = dbex.EntityValidationErrors.ToList(); //} catch (DbUpdateException ex) { _exceptionParser.ThrowUniqueConstraintException(ex); } catch (AmbiguousMatchException ex) { Log.Error("Ambiguous Match Exception", ex); throw ex; } }So, I get my entities to the client application (browser), using JavaScript I add or delete some links in the Sales Channel scspLink related entities. Now I need to save all my changes to the database. Right now I found that only the Sales Channel changes are saved but not the related entities. Do you have a simple method of dealing with the problem?