/// <summary> /// /// </summary> /// <typeparam name="TContextType"></typeparam> /// <returns></returns> public TContextType GetContext <TContextType>() where TContextType : DbContext { try { var connection = ConnectionBuilder.GetConnection(); return((TContextType)Activator.CreateInstance( typeof(TContextType), connection, this.GenerateCompiledModel(connection), true)); } catch (TargetInvocationException ex) { // Rethrow the inner exception as that is what we are actually interested in. ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); throw; } }