title: Is it possible to convert ObjectSet to DbSet in Entity Framework 6?
body: <p>I am working on upgrading a WPF application from using .Net4/EF 4.4 to .Net4.5/EF 6.1.  After the upgrade I will use DbContext (since there was no POCO-generator for ObjectContext).</p>
  
  <p>The application use a Repository/UnitOfWork-pattern to access Entity Framework, and before the upgrade I could set the ObjectSet.MergeOption to OverwriteChanges (in the repository-class), but the DbSet-class does not have this feature. However, I know that I can get to a ObjectSet from the DbContext by using the IObjectContextAdapter. (See code below). But it seems that setting the MergeOption on the created ObjectSet will not reflect back to the DbSet.</p>
  
  <p>So my question is this: is there any way to convert the ObjectSet back to a DbSet (conserving the MergeOption-setting)?</p>
  
  <p>This is some of the repository class:</p>
  
  <pre><code>public class SqlRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class, IEntity
  {
      protected DbSet&lt;T&gt; dbSet;
  
      public SqlRepository(DbContext context)
      {
          var objectContext = ((IObjectContextAdapter)context).ObjectContext;
          var set = objectContext.CreateObjectSet&lt;T&gt;();
          set.MergeOption = MergeOption.OverwriteChanges;
  
  
          dbSet = context.Set&lt;T&gt;();
  //I would like to do something like this: dbSet = (DbSet)set;
  
  
      }
  }
  </code></pre>