Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually you are talking about <code>AddObject</code> method of <code>ObjectSet&lt;TEntity&gt;</code> class which was used by old <code>ObjectContext</code>. But since Entity Framework 4 we have <code>DbContext</code> class (which is a wrapper over old <code>ObjectContext</code>). This new class uses <code>DbSet&lt;TEntity&gt;</code> instead of old <code>ObjectSet&lt;TEntity&gt;</code>. New set class has method <code>Add</code>.</p> <p>So, back to differences. Old implementation invoked <code>AddObject</code> method of <code>ObjectContext</code>:</p> <pre><code>public void AddObject(TEntity entity) { Context.AddObject(FullyQualifiedEntitySetName, entity); } </code></pre> <p>New implementation does same thing (see action parameter):</p> <pre><code>public virtual void Add(object entity) { ActOnSet(() =&gt; ((InternalSet&lt;TEntity&gt;) this).InternalContext.ObjectContext.AddObject(((InternalSet&lt;TEntity&gt;) this).EntitySetName, entity), EntityState.Added, entity, "Add"); } </code></pre> <p>As you can see same <code>ObjectContext.AddObject</code> method is called internally. What was changed - previously we just added entity to context, but now if there is state entry exists in ObjectStateManager, then we just changing state of entry to <code>Added</code>:</p> <pre><code>if (InternalContext.ObjectContext.ObjectStateManager.TryGetObjectStateEntry(entity, out entry)) { entry.ChangeState(newState); // just change state } else { action(); // invoke ObjectContext.AddObject } </code></pre> <p>Main goal of new API is making <code>DbContext</code> easier to use.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload