public virtual void Insert(TEntity entity)

Sep 18, 2014 at 11:40 AM
I am wandering if the implementation of the following function is correct. It seems to me that Add should be used instead of Attach.
public virtual void Insert(TEntity entity)
            entity.ObjectState = ObjectState.Added;
            _dbSet.Attach(entity); // I think it should be _dbSet.Add(entity)
I have found this because I was trying to save an entity with 2 or more sub items and it complaint because the subitems could not be attached to the graph as they both had id of 0.
Sep 19, 2014 at 6:25 AM
Edited Sep 19, 2014 at 6:26 AM
You need to you IRepository.InsertOrUpdateGraph(entity).
Marked as answer by lelong37 on 9/18/2014 at 11:26 PM
Sep 19, 2014 at 1:19 PM
So for every new Entity I need to call InsertOrUpdateGraph in the repository?

Why this InsertOrUpdateGraph is not implemented in the Service?
Sep 22, 2014 at 5:58 AM
This is a bug, InsertOrUpdateGraph needs to be on the IService and Service, for now feel free to implement this directly, we will release an update with this fix shortly.

Thank you for notifying us with this issue.
Nov 10, 2014 at 10:00 PM
Edited Nov 11, 2014 at 1:44 AM
I would like to manage associated entities via a Web API controller. Do you have any examples of using InsertOrUpdateGraph in any of the following scenarios?
  1. Existing entity with all children added
  2. Existing entity with some children existing, some children added and some children deleted?
Do each of the child states have to be specified for it to work correctly?