public static void ConfigureLogging( this DbContext db, Action <string> logger, Func <string, LogLevel, bool> filter) { var serviceProvider = db.GetInfrastructure <IServiceProvider>(); var loggerFactory = (ILoggerFactory)serviceProvider.GetService(typeof(ILoggerFactory)); LogProvider.CreateOrModifyLoggerForDbContext(db.GetType(), loggerFactory, logger, filter); }
public static Task <ExecutionResult> ExecuteGraphQLQueryAsync(this DbContext context, string query, IDictionary <string, object> variables, string operationName = null, CancellationToken cancellationToken = default(CancellationToken)) { var exectutor = context.GetInfrastructure().GetService <GraphQLExecutor>(); if (exectutor == null) { throw new InvalidOperationException("This context is not enabled for GraphQL. Add GraphQL to context services with .AddGraphQL()"); } return(exectutor.ExecuteAsync(context, query, variables, operationName, cancellationToken)); }
/// <summary> /// Creates a proxy instance for an entity type if proxy creation has been turned on. /// </summary> /// <param name="context"> The <see cref="DbContext" />. </param> /// <param name="entityType"> The entity type for which a proxy is needed. </param> /// <param name="constructorArguments"> Arguments to pass to the entity type constructor. </param> /// <returns> The proxy instance. </returns> public static object CreateProxy( [NotNull] this DbContext context, [NotNull] Type entityType, [NotNull] params object[] constructorArguments) { Check.NotNull(context, nameof(context)); Check.NotNull(entityType, nameof(entityType)); Check.NotNull(constructorArguments, nameof(constructorArguments)); return(context.GetInfrastructure().CreateProxy(entityType, constructorArguments)); }
public static async Task MigrateUpByStepAsync(this DbContext dbContext) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } var migrator = dbContext.GetInfrastructure().GetService <IMigrator>(); await dbContext.Database.EnsureDeletedAsync(); foreach (var migration in dbContext.Database.GetMigrations()) { await migrator.MigrateAsync(migration); } }
public static async Task MigrateDownByStepAsync(this DbContext dbContext) { _ = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); var migrator = dbContext.GetInfrastructure().GetService <IMigrator>(); await dbContext.Database.EnsureDeletedAsync(); await migrator.MigrateAsync(null); foreach (var migration in dbContext.Database.GetMigrations().Reverse()) { await migrator.MigrateAsync(migration); } await migrator.MigrateAsync("0");//delete all the things that migration created }
public static IDbProperties GetDbProperties(this DbContext context) { return(context.GetInfrastructure().GetRequiredService <IDbProperties>()); }