In our framework we have a generic base class that the developers can use to override certain parts of the application.
/// <summary> public partial class PersistentObjectActions<TContext, TEntity> : IPersistentObjectActions where TContext : ObjectContext where TEntity : class { // snip public TContext Context { get; private set; } // snip protected virtual void SaveExisting(PersistentObject obj, TEntity entity) { if (entity == null) obj.ThrowNotFound(); obj.PopulateObjectValues(entity, Context); if (CheckRules(obj, entity)) { Context.SaveChanges(); if (!obj.IsInBulkEditMode) obj.PopulateAttributeValues(entity); } } //snip }
This allows developers to still work with their ObjectContext class and allows us to call the methods like SaveChanges, DeleteObject,...
But with the trend going for DbContext (and now the announcement that DbContext is used as default) I was looking for the easiest way to support both (and maintaining type safety). Looks like I'm going to have to remove the where TContext : ObjectContext part and add an extra ObjectContext property.