Exemple #1
0
        private async Task DisposeAsyncCore()
        {
            if (_context != null)
            {
                await _context.DisposeAsync().ConfigureAwait(false);
            }

            _context = null;
        }
Exemple #2
0
    public void Initialize()
    {
        bookLibraryContext = dBContextService.GetBookLibraryContext(out var dataSourcePath);
        entityService.BookLibraryContext = bookLibraryContext;

        ShellViewModel.PropertyChanged += ShellViewModelPropertyChanged;
        ShellViewModel.SaveCommand      = saveCommand;
        ShellViewModel.DatabasePath     = dataSourcePath;
    }
Exemple #3
0
 public InterceptionResult <int> CommandNonQueryExecuting(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     CommandSource commandSource)
 => default;
 /// <summary>
 ///     <para>
 ///         Creates a new parameter object for the given parameters.
 ///     </para>
 ///     <para>
 ///         This type is typically used by database providers (and other extensions). It is generally
 ///         not used in application code.
 ///     </para>
 /// </summary>
 /// <param name="connection"> The connection on which the command will execute. </param>
 /// <param name="parameterValues"> The SQL parameter values to use, or <see langword="null"/> if none. </param>
 /// <param name="readerColumns"> The expected columns if the reader needs to be buffered, or <see langword="null"/> otherwise. </param>
 /// <param name="context"> The current <see cref="DbContext" /> instance, or <see langword="null"/> if it is not known. </param>
 /// <param name="logger"> A logger, or <see langword="null"/> if no logger is available. </param>
 public RelationalCommandParameterObject(
     IRelationalConnection connection,
     IReadOnlyDictionary <string, object?>?parameterValues,
     IReadOnlyList <ReaderColumn>?readerColumns,
     DbContext?context,
     IRelationalCommandDiagnosticsLogger?logger)
     : this(connection, parameterValues, readerColumns, context, logger, detailedErrorsEnabled : false)
 {
 }
 public InterceptionResult <DbDataReader> CommandReaderExecuting(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     CommandSource commandSource)
 => default;
 public InterceptionResult <DbCommand> CommandCreating(
     IRelationalConnection connection,
     DbCommandMethod commandMethod,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     CommandSource commandSource)
 => default;
Exemple #7
0
 public RelationalCommandParameterObject(
     [NotNull] IRelationalConnection connection,
     [CanBeNull] IReadOnlyDictionary <string, object?>?parameterValues,
     [CanBeNull] IReadOnlyList <ReaderColumn>?readerColumns,
     [CanBeNull] DbContext?context,
     [CanBeNull] IDiagnosticsLogger <DbLoggerCategory.Database.Command>?logger)
     : this(connection, parameterValues, readerColumns, context, logger, detailedErrorsEnabled : false)
 {
 }
Exemple #8
0
        public void Initialize()
        {
            bookLibraryContext = dBContextService.GetBookLibraryContext(out var dataSourcePath);
            entityService.BookLibraryContext = bookLibraryContext;

            PropertyChangedEventManager.AddHandler(ShellViewModel, ShellViewModelPropertyChanged, "");
            ShellViewModel.SaveCommand  = saveCommand;
            ShellViewModel.DatabasePath = dataSourcePath;
        }
Exemple #9
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                _context?.Dispose();
            }

            _context = null;
        }
Exemple #10
0
 public ValueTask <InterceptionResult <int> > CommandNonQueryExecutingAsync(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     CancellationToken cancellationToken = default)
 => default;
Exemple #11
0
 public DbCommand CommandCreated(
     IRelationalConnection connection,
     DbCommand command,
     DbCommandMethod commandMethod,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     TimeSpan duration)
 => command;
Exemple #12
0
 public int CommandNonQueryExecuted(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     int methodResult,
     DateTimeOffset startTime,
     TimeSpan duration)
 => methodResult;
Exemple #13
0
 public object?CommandScalarExecuted(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     object?methodResult,
     DateTimeOffset startTime,
     TimeSpan duration)
 => methodResult;
Exemple #14
0
 public DbDataReader CommandReaderExecuted(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DbDataReader methodResult,
     DateTimeOffset startTime,
     TimeSpan duration)
 => methodResult;
Exemple #15
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual async Task <bool> CreateDatabaseIfNotExistsOnceAsync(
            DbContext?_,
            ThroughputProperties?throughput,
            CancellationToken cancellationToken = default)
        {
            var response = await Client.CreateDatabaseIfNotExistsAsync(_databaseId, throughput, cancellationToken : cancellationToken)
                           .ConfigureAwait(false);

            return(response.StatusCode == HttpStatusCode.Created);
        }
Exemple #16
0
        public virtual async Task <bool> CreateDatabaseIfNotExistsOnceAsync(
            [CanBeNull] DbContext?_,
            [CanBeNull] object?__,
            CancellationToken cancellationToken = default)
        {
            var response = await Client.CreateDatabaseIfNotExistsAsync(_databaseId, cancellationToken : cancellationToken)
                           .ConfigureAwait(false);

            return(response.StatusCode == HttpStatusCode.Created);
        }
Exemple #17
0
 public ValueTask <InterceptionResult <DbDataReader> > CommandReaderExecutingAsync(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     CommandSource commandSource,
     CancellationToken cancellationToken = default)
 => default;
Exemple #18
0
        public DbSeed(IDbContext dbContext)
        {
            DbContext?efCoreDbContext = dbContext as DbContext;

            if (efCoreDbContext == null)
            {
                throw new Exception("DbSeed supports only EfCore.DbContext");
            }
            _dbContext = efCoreDbContext;
        }
Exemple #19
0
 /// <summary>
 ///     Creates a new instance of the command.
 /// </summary>
 /// <param name="relationalCommand">The underlying <see cref="IRelationalCommand" /> that will be used to execute the command.</param>
 /// <param name="context">The current <see cref="DbContext" /> or null if not known.</param>
 /// <param name="logger">The command logger.</param>
 /// <param name="transactionSuppressed">Indicates whether or not transactions should be suppressed while executing the command.</param>
 public MigrationCommand(
     IRelationalCommand relationalCommand,
     DbContext?context,
     IRelationalCommandDiagnosticsLogger logger,
     bool transactionSuppressed = false)
 {
     _relationalCommand    = relationalCommand;
     _context              = context;
     CommandLogger         = logger;
     TransactionSuppressed = transactionSuppressed;
 }
Exemple #20
0
 public ValueTask <DbDataReader> CommandReaderExecutedAsync(
     IRelationalConnection connection,
     DbCommand command,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DbDataReader methodResult,
     DateTimeOffset startTime,
     TimeSpan duration,
     CancellationToken cancellationToken = default)
 => new(methodResult);
Exemple #21
0
 /// <summary>
 /// Creates instance of context.
 /// </summary>
 /// <param name="context">EF.Core database context.</param>
 /// <param name="dataProvider">lin2db database provider instance.</param>
 /// <param name="connectionString">Connection string.</param>
 /// <param name="model">EF.Core model.</param>
 /// <param name="transformFunc">Expression converter.</param>
 public LinqToDBForEFToolsDataContext(
     DbContext?context,
     IDataProvider dataProvider,
     string connectionString,
     IModel model,
     Func <Expression, IDataContext, DbContext?, IModel, Expression>?transformFunc) : base(dataProvider, connectionString)
 {
     _context       = context;
     _model         = model;
     _transformFunc = transformFunc;
 }
 /// <summary>
 ///     Constructs the event payload.
 /// </summary>
 /// <param name="eventDefinition"> The event definition. </param>
 /// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
 /// <param name="connection"> The <see cref="DbConnection" />. </param>
 /// <param name="context"> The <see cref="DbContext" /> currently being used, to null if not known. </param>
 /// <param name="connectionId"> A correlation ID that identifies the <see cref="DbConnection" /> instance being used. </param>
 /// <param name="async"> Indicates whether or not the operation is happening asynchronously. </param>
 /// <param name="startTime"> The start time of this event. </param>
 /// <param name="duration"> The duration this event. </param>
 public ConnectionEndEventData(
     EventDefinitionBase eventDefinition,
     Func <EventDefinitionBase, EventData, string> messageGenerator,
     DbConnection connection,
     DbContext?context,
     Guid connectionId,
     bool async,
     DateTimeOffset startTime,
     TimeSpan duration)
     : base(eventDefinition, messageGenerator, connection, context, connectionId, async, startTime)
     => Duration = duration;
Exemple #23
0
 public DbCommand CommandInitialized(
     IRelationalConnection connection,
     DbCommand command,
     DbCommandMethod commandMethod,
     DbContext?context,
     Guid commandId,
     Guid connectionId,
     DateTimeOffset startTime,
     TimeSpan duration,
     CommandSource commandSource)
 => command;
Exemple #24
0
 public TransactionEndEventData(
     [NotNull] EventDefinitionBase eventDefinition,
     [NotNull] Func <EventDefinitionBase, EventData, string> messageGenerator,
     [NotNull] DbTransaction transaction,
     [CanBeNull] DbContext?context,
     Guid transactionId,
     Guid connectionId,
     bool async,
     DateTimeOffset startTime,
     TimeSpan duration)
     : base(eventDefinition, messageGenerator, transaction, context, transactionId, connectionId, async, startTime)
     => Duration = duration;
Exemple #25
0
 public ConnectionErrorEventData(
     [NotNull] EventDefinitionBase eventDefinition,
     [NotNull] Func <EventDefinitionBase, EventData, string> messageGenerator,
     [NotNull] DbConnection connection,
     [CanBeNull] DbContext?context,
     Guid connectionId,
     [NotNull] Exception exception,
     bool async,
     DateTimeOffset startTime,
     TimeSpan duration)
     : base(eventDefinition, messageGenerator, connection, context, connectionId, async, startTime, duration)
     => Exception = exception;
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _dbContextTransaction?.Dispose();
            _dbContext?.Dispose();
            _dbContext            = null;
            _dbContextTransaction = null;
            base.Dispose();
        }
Exemple #27
0
        public MigrationCommand(
            [NotNull] IRelationalCommand relationalCommand,
            [CanBeNull] DbContext?context,
            [NotNull] IDiagnosticsLogger <DbLoggerCategory.Database.Command> logger,
            bool transactionSuppressed = false)
        {
            Check.NotNull(relationalCommand, nameof(relationalCommand));

            _relationalCommand    = relationalCommand;
            _context              = context;
            CommandLogger         = logger;
            TransactionSuppressed = transactionSuppressed;
        }
        public override async ValueTask DisposeAsync()
        {
            if (_context != null)
            {
                await _context.DisposeAsync().ConfigureAwait(false);
            }

            _context = null;
            Dispose(false);
            await base.DisposeAsync();

            GC.SuppressFinalize(this);
        }
 /// <summary>
 ///     Constructs the event payload.
 /// </summary>
 /// <param name="eventDefinition"> The event definition. </param>
 /// <param name="messageGenerator"> A delegate that generates a log message for this event. </param>
 /// <param name="connection"> The <see cref="DbConnection" />. </param>
 /// <param name="context"> The <see cref="DbContext" /> currently being used, to null if not known. </param>
 /// <param name="connectionId"> A correlation ID that identifies the <see cref="DbConnection" /> instance being used. </param>
 /// <param name="async"> Indicates whether or not the operation is happening asynchronously. </param>
 /// <param name="startTime"> The start time of this event. </param>
 public ConnectionEventData(
     EventDefinitionBase eventDefinition,
     Func <EventDefinitionBase, EventData, string> messageGenerator,
     DbConnection connection,
     DbContext?context,
     Guid connectionId,
     bool async,
     DateTimeOffset startTime)
     : base(eventDefinition, messageGenerator, context)
 {
     Connection   = connection;
     ConnectionId = connectionId;
     IsAsync      = async;
     StartTime    = startTime;
 }
Exemple #30
0
 /// <summary>
 /// Creates new instance of data connection.
 /// </summary>
 /// <param name="context">EF.Core database context.</param>
 /// <param name="dataProvider">linq2db database provider.</param>
 /// <param name="connectionString">Connection string.</param>
 /// <param name="model">EF.Core data model.</param>
 /// <param name="transformFunc">Expression converter.</param>
 public LinqToDBForEFToolsDataConnection(
     DbContext?context,
     [NotNull]   IDataProvider dataProvider,
     [NotNull]   string connectionString,
     IModel?model,
     Func <Expression, IDataContext, DbContext?, IModel?, Expression>?transformFunc) : base(dataProvider, connectionString)
 {
     Context        = context;
     _model         = model;
     _transformFunc = transformFunc;
     if (LinqToDBForEFTools.EnableChangeTracker)
     {
         OnEntityCreated += OnEntityCreatedHandler;
     }
 }