title: EntityObject to DbContext
body: <p>I am not sure in terms of exact technical specification for this problem to me but in simple words I am trying to create a wrapper/extension method around to save my entities. </p>
  
  <p>So I added new Entity Data Model (.edmx) file to my project. That generates DbSet(s) like this- </p>
  
  <pre><code> public partial class SUContextContainer : DbContext
      {
          public SUContextContainer()
              : base("name=SUContextContainer")
          {
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              throw new UnintentionalCodeFirstException();
          }
  
          public DbSet&lt;Category&gt; Categories { get; set; }
          public DbSet&lt;Gallery&gt; Galleries { get; set; }
          public DbSet&lt;SuperUser&gt; SuperUsers { get; set; }
          public DbSet&lt;UserType&gt; UserTypes { get; set; }
      }
  </code></pre>
  
  <p>Now here I am trying to wrap this into an extension method for database operations like (save, delete, update etc..)</p>
  
  <p>I tried creating it as - </p>
  
  <pre><code> public static void Save(this EntityObject objEntity)
          {
              try                                                         // Update Record
              {
                  ((IObjectContextAdapter)Global.Context).ObjectContext.ObjectStateManager.ChangeObjectState(objEntity, EntityState.Modified);
                  Global.Context.SaveChanges();
              }
              catch (OptimisticConcurrencyException)                      // Insert Record
              {
                  ((IObjectContextAdapter)Global.Context).ObjectContext.ObjectStateManager.ChangeObjectState(objEntity, EntityState.Added);
                  Global.Context.SaveChanges();
              }
          }
  </code></pre>
  
  <p>This method is attached to EntityObject types. Where .edmx code which it generates are of type DbContext. </p>
  
  <p>So Whenever I try to save some entity with this helper method it never finds out. </p>
  
  <pre><code> var galleryEntity = new Gallery {
         IsActive = true,
         CategoryId = model.CategoryId,
       };
    galleryEntity.Save(); // the save method is not found. 
  </code></pre>
  
  <p>I tried above method to change in - </p>
  
  <pre><code> public static void Save(this DbSet objEntity)
  </code></pre>
  
  <p>But this also doesn't seem to take as extension method. 
  What am I doing wrong.</p>