I have extension method that does something like this
public static void DoStuff(this ObjectContext context)
{
using(var newContext = new MyEntitiesContext())
{
// do stuff
newContext.SaveChanges();
}
context.SaveChanges();
}
I was wondering if there a way to new a context of the same type as the context passed in instead of specifying MyEntitiesContext?
Thanks in advance
If you don’t mind reflection:
Now you either need a base Type or – if you still don’t mind reflection – you can simply call the method by name. Or, since you are using C#4 you could go with dynamic.
Edit: You could also Go this way: