Where am I creating multiple instances of DbContext? (Entity Framework)
<p>I have the following structure of repositories:</p>

<pre><code>public class Repository&lt;T&gt; where T : class
{
    protected DataContext context = null;

    protected DbSet&lt;T&gt; DbSet
    {
        get; set;
    }

    public Repository()
    {
        context = new DataContext();
        DbSet = context.Set&lt;T&gt;();

    }

    public Repository(DataContext context)
    {
        this.context = context;
    }
}
</code></pre>

<p>...</p>

<pre><code>public class PlayerpostRepository : Repository&lt;PlayerPost&gt;
{
    public PlayerpostRepository(DataContext context)
    {
        this.context = context;
    }
}
</code></pre>

<p>...</p>

<pre><code>public class PlayerRepository : Repository&lt;Player&gt;
{

    public PlayerRepository(DataContext context)
    {
        this.context = context;
    }
}
</code></pre>

<p>And in my controller, I create the instances like this:</p>

<pre><code>private static DataContext db = new DataContext();
    private PlayerpostRepository repository = new PlayerpostRepository(db);
    private PlayerRepository playerrep = new PlayerRepository(db);
</code></pre>

<p>But when I call the <code>repository.SaveChanges()</code> method in the controller, I get the following error:</p>

<blockquote>
  <p>entity object cannot be referenced by multiple instances of IEntityChangeTracker</p>
</blockquote>

<p>Which, if I understand it correctly, means that I have created multiple instances of <code>DbContext</code> which are connected to one object. I don't see where that is happening.</p>