/// <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 SqlServerValueGenerationStrategyConvention([NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> logger) { Logger = logger; }
public CustomSqliteDatabaseModelFactory(IDiagnosticsLogger <DbLoggerCategory.Scaffolding> logger) { _logger = logger; }
public SqlExpression?Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger) { if (typeof(JToken).IsAssignableFrom(method.DeclaringType) && method.Name == "get_Item" && arguments.Count == 1) { return((instance is ColumnExpression columnExpression ? _sqlExpressionFactory.JsonTraversal( columnExpression, returnsText: false, typeof(string), instance.TypeMapping) : instance) is PostgresJsonTraversalExpression prevPathTraversal ? prevPathTraversal.Append(_sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0])) : null); } if (arguments.FirstOrDefault() is PostgresJsonTraversalExpression traversal) { // Support for .Value<T>() and .Value<U, T>(): if (instance == null && method.Name == nameof(Extensions.Value) && method.DeclaringType == typeof(Extensions) && method.IsGenericMethod && method.GetParameters().Length == 1 && arguments.Count == 1) { var traversalToText = new PostgresJsonTraversalExpression( traversal.Expression, traversal.Path, returnsText: true, typeof(string), _stringTypeMapping); if (method.ReturnType == typeof(string)) { return(traversalToText); } else { return(_sqlExpressionFactory.Convert(traversalToText, method.ReturnType, _typeMappingSource.FindMapping(method.ReturnType))); } } // Support for Count() if (instance == null && method.Name == nameof(Enumerable.Count) && method.DeclaringType == typeof(Enumerable) && method.IsGenericMethod && method.GetParameters().Length == 1 && arguments.Count == 1) { return(_jsonPocoTranslator.TranslateArrayLength(traversal)); } // Predicate-less Any - translate to a simple length check. if (method.IsClosedFormOf(_enumerableAnyWithoutPredicate) && arguments.Count == 1 && arguments[0].Type.TryGetElementType(out _) && arguments[0].TypeMapping is NpgsqlJsonTypeMapping) { return(_sqlExpressionFactory.GreaterThan( _jsonPocoTranslator.TranslateArrayLength(arguments[0]), _sqlExpressionFactory.Constant(0))); } } return(null); }
// ReSharper disable once InconsistentNaming private static IEnumerable <TEntity> _FastQuery <TEntity>( RelationalQueryContext relationalQueryContext, ShaperCommandContext shaperCommandContext, Func <DbDataReader, TEntity> materializer, Type contextType, IDiagnosticsLogger <DbLoggerCategory.Query> logger) { relationalQueryContext.Connection.Open(); RelationalDataReader dataReader; try { var relationalCommand = shaperCommandContext .GetRelationalCommand(relationalQueryContext.ParameterValues); dataReader = relationalCommand.ExecuteReader( relationalQueryContext.Connection, relationalQueryContext.ParameterValues); } catch { // If failure happens creating the data reader, then it won't be available to // handle closing the connection, so do it explicitly here to preserve ref counting. relationalQueryContext.Connection.Close(); throw; } var dbDataReader = dataReader.DbDataReader; try { using (dataReader) { using (relationalQueryContext.ConcurrencyDetector.EnterCriticalSection()) // TODO: IDisposable box? { while (true) { bool hasNext; try { hasNext = dataReader.Read(); } catch (Exception exception) { logger.QueryIterationFailed(contextType, exception); throw; } if (hasNext) { yield return(materializer(dbDataReader)); } else { yield break; } } } } } finally { relationalQueryContext.Connection?.Close(); relationalQueryContext.Dispose(); } }
public ChangeDetectorProxy( IDiagnosticsLogger <DbLoggerCategory.ChangeTracking> logger, ILoggingOptions loggingOptions) : base(logger, loggingOptions) { }
/// <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> protected virtual void ValidateSharedContainerCompatibility( [NotNull] IReadOnlyList <IEntityType> mappedTypes, [NotNull] string container, [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger) { var discriminatorValues = new Dictionary <object, IEntityType>(); IProperty partitionKey = null; IEntityType firstEntityType = null; foreach (var entityType in mappedTypes) { var partitionKeyPropertyName = entityType.GetPartitionKeyPropertyName(); if (partitionKeyPropertyName != null) { var nextPartitionKeyProperty = entityType.FindProperty(partitionKeyPropertyName); if (nextPartitionKeyProperty == null) { throw new InvalidOperationException( CosmosStrings.PartitionKeyMissingProperty(entityType.DisplayName(), partitionKeyPropertyName)); } var keyType = nextPartitionKeyProperty.GetTypeMapping().Converter?.ProviderClrType ?? nextPartitionKeyProperty.ClrType; if (keyType != typeof(string)) { throw new InvalidOperationException( CosmosStrings.PartitionKeyNonStringStoreType( partitionKeyPropertyName, entityType.DisplayName(), keyType.ShortDisplayName())); } if (partitionKey == null) { if (firstEntityType != null) { throw new InvalidOperationException(CosmosStrings.NoPartitionKey(firstEntityType.DisplayName(), container)); } partitionKey = nextPartitionKeyProperty; } else if (partitionKey.GetPropertyName() != nextPartitionKeyProperty.GetPropertyName()) { throw new InvalidOperationException( CosmosStrings.PartitionKeyStoreNameMismatch( partitionKey.Name, firstEntityType.DisplayName(), partitionKey.GetPropertyName(), nextPartitionKeyProperty.Name, entityType.DisplayName(), nextPartitionKeyProperty.GetPropertyName())); } } else if (partitionKey != null) { throw new InvalidOperationException(CosmosStrings.NoPartitionKey(entityType.DisplayName(), container)); } if (mappedTypes.Count == 1) { break; } if (firstEntityType == null) { firstEntityType = entityType; } if (entityType.ClrType?.IsInstantiable() == true && entityType.GetContainingPropertyName() == null) { if (entityType.GetDiscriminatorProperty() == null) { throw new InvalidOperationException( CosmosStrings.NoDiscriminatorProperty(entityType.DisplayName(), container)); } var discriminatorValue = entityType.GetDiscriminatorValue(); if (discriminatorValue == null) { throw new InvalidOperationException( CosmosStrings.NoDiscriminatorValue(entityType.DisplayName(), container)); } if (discriminatorValues.TryGetValue(discriminatorValue, out var duplicateEntityType)) { throw new InvalidOperationException( CosmosStrings.DuplicateDiscriminatorValue( entityType.DisplayName(), discriminatorValue, duplicateEntityType.DisplayName(), container)); } discriminatorValues[discriminatorValue] = entityType; } } }
/// <summary> /// 执行 /// </summary> /// <param name="migrationCommands">迁移命令</param> /// <param name="connection">连接对象</param> /// <param name="logger">日志</param> public void ExecuteNonQuery( IEnumerable <MigrationCommand> migrationCommands, IRelationalConnection connection, IDiagnosticsLogger <DbLoggerCategory.Database> logger = null) { try { if (Check.IsTraceEnabled(logger?.Logger)) { Trace <DbLoggerCategory.Database> .Write(logger, LogLevel.Trace, OracleTraceTag.Entry, OracleTraceClassName.OracleMigrationCommandExecutor, OracleTraceFuncName.ExecuteNonQuery); } m_oracleLogger = logger; Check.NotNull(migrationCommands, nameof(migrationCommands)); Check.NotNull(connection, nameof(connection)); using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { connection.Open(); try { IDbContextTransaction dbContextTransaction = null; try { foreach (MigrationCommand migrationCommand in migrationCommands) { if (dbContextTransaction == null && !migrationCommand.TransactionSuppressed) { dbContextTransaction = connection.BeginTransaction(); } if (dbContextTransaction != null && migrationCommand.TransactionSuppressed) { dbContextTransaction.Commit(); dbContextTransaction.Dispose(); dbContextTransaction = null; } try { migrationCommand.ExecuteNonQuery(connection); } catch (Exception ex) { if (!migrationCommand.CommandText.StartsWith("CREATE UNIQUE INDEX") || (!ex.Message.Contains("ORA-01408") && !ex.Message.Contains("ORA-00955"))) { throw; } } } dbContextTransaction?.Commit(); } finally { dbContextTransaction?.Dispose(); } } finally { connection.Close(); } } } catch (Exception ex) { if (Check.IsErrorEnabled(logger?.Logger)) { Trace <DbLoggerCategory.Database> .Write(m_oracleLogger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleMigrationCommandExecutor, OracleTraceFuncName.ExecuteNonQuery, ex.ToString()); } throw; } finally { if (Check.IsTraceEnabled(logger?.Logger)) { Trace <DbLoggerCategory.Database> .Write(m_oracleLogger, LogLevel.Trace, OracleTraceTag.Exit, OracleTraceClassName.OracleMigrationCommandExecutor, OracleTraceFuncName.ExecuteNonQuery); } } }
public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger) { if (method.Equals(TrimWithoutArgsMethod)) { return(_fbSqlExpressionFactory.Trim("BOTH", null, instance)); } if (method.Equals(TrimWithCharArgMethod)) { return(_fbSqlExpressionFactory.Trim("BOTH", arguments[0], instance)); } if (method.Equals(TrimEndWithoutArgsMethod)) { return(_fbSqlExpressionFactory.Trim("TRAILING", null, instance)); } if (method.Equals(TrimEndWithCharArgMethod)) { return(_fbSqlExpressionFactory.Trim("TRAILING", arguments[0], instance)); } if (method.Equals(TrimStartWithoutArgsMethod)) { return(_fbSqlExpressionFactory.Trim("LEADING", null, instance)); } if (method.Equals(TrimStartWithCharArgMethod)) { return(_fbSqlExpressionFactory.Trim("LEADING", arguments[0], instance)); } return(null); }
protected override IRelationalCommandBuilder CreateCore( [NotNull] IDiagnosticsLogger <DbLoggerCategory.Database.Command> logger, [NotNull] IRelationalTypeMapper relationalTypeMapper) { return(new MySQLCommandBuilder(_logger, _typeMapper)); }
/// <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 SqlExpression?Translate( SqlExpression?instance, MemberInfo member, Type returnType, IDiagnosticsLogger <DbLoggerCategory.Query> logger) { Check.NotNull(member, nameof(member)); Check.NotNull(returnType, nameof(returnType)); Check.NotNull(logger, nameof(logger)); if (instance != null) { if (_memberToFunctionName.TryGetValue(member, out var functionName)) { return(returnType == typeof(bool) ? _sqlExpressionFactory.Case( new[] { new CaseWhenClause( _sqlExpressionFactory.IsNotNull(instance), _sqlExpressionFactory.Function( functionName, new[] { instance }, nullable: false, argumentsPropagateNullability: new[] { false }, returnType)) }, null) : (SqlExpression)_sqlExpressionFactory.Function( functionName, new[] { instance }, nullable: true, argumentsPropagateNullability: new[] { true }, returnType)); } if (Equals(member, _geometryType)) { return(_sqlExpressionFactory.Case( _sqlExpressionFactory.Function( "rtrim", new SqlExpression[] { _sqlExpressionFactory.Function( "GeometryType", new[] { instance }, nullable: true, argumentsPropagateNullability: new[] { true }, returnType), _sqlExpressionFactory.Constant(" ZM") }, nullable: true, argumentsPropagateNullability: new[] { true }, returnType), new[] { new CaseWhenClause(_sqlExpressionFactory.Constant("POINT"), _sqlExpressionFactory.Constant("Point")), new CaseWhenClause(_sqlExpressionFactory.Constant("LINESTRING"), _sqlExpressionFactory.Constant("LineString")), new CaseWhenClause(_sqlExpressionFactory.Constant("POLYGON"), _sqlExpressionFactory.Constant("Polygon")), new CaseWhenClause(_sqlExpressionFactory.Constant("MULTIPOINT"), _sqlExpressionFactory.Constant("MultiPoint")), new CaseWhenClause( _sqlExpressionFactory.Constant("MULTILINESTRING"), _sqlExpressionFactory.Constant("MultiLineString")), new CaseWhenClause(_sqlExpressionFactory.Constant("MULTIPOLYGON"), _sqlExpressionFactory.Constant("MultiPolygon")), new CaseWhenClause( _sqlExpressionFactory.Constant("GEOMETRYCOLLECTION"), _sqlExpressionFactory.Constant("GeometryCollection")) }, null)); } if (Equals(member, _ogcGeometryType)) { return(_sqlExpressionFactory.Case( _sqlExpressionFactory.Function( "rtrim", new SqlExpression[] { _sqlExpressionFactory.Function( "GeometryType", new[] { instance }, nullable: true, argumentsPropagateNullability: new[] { true }, typeof(string)), _sqlExpressionFactory.Constant(" ZM") }, nullable: true, argumentsPropagateNullability: new[] { true }, typeof(string)), new[] { new CaseWhenClause(_sqlExpressionFactory.Constant("POINT"), _sqlExpressionFactory.Constant(OgcGeometryType.Point)), new CaseWhenClause( _sqlExpressionFactory.Constant("LINESTRING"), _sqlExpressionFactory.Constant(OgcGeometryType.LineString)), new CaseWhenClause( _sqlExpressionFactory.Constant("POLYGON"), _sqlExpressionFactory.Constant(OgcGeometryType.Polygon)), new CaseWhenClause( _sqlExpressionFactory.Constant("MULTIPOINT"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPoint)), new CaseWhenClause( _sqlExpressionFactory.Constant("MULTILINESTRING"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiLineString)), new CaseWhenClause( _sqlExpressionFactory.Constant("MULTIPOLYGON"), _sqlExpressionFactory.Constant(OgcGeometryType.MultiPolygon)), new CaseWhenClause( _sqlExpressionFactory.Constant("GEOMETRYCOLLECTION"), _sqlExpressionFactory.Constant(OgcGeometryType.GeometryCollection)) }, null)); } } return(null); }
/// <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 SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger) { Check.NotNull(method, nameof(method)); Check.NotNull(arguments, nameof(arguments)); Check.NotNull(logger, nameof(logger)); if (method.IsGenericMethod && method.GetGenericMethodDefinition().Equals(EnumerableMethods.Contains) && arguments[0].Type == typeof(byte[])) { var source = arguments[0]; var value = arguments[1] is SqlConstantExpression constantValue ? (SqlExpression)_sqlExpressionFactory.Constant(new[] { (byte)constantValue.Value }, source.TypeMapping) : _sqlExpressionFactory.Function( "char", new[] { arguments[1] }, nullable: false, argumentsPropagateNullability: new[] { false }, typeof(string)); return(_sqlExpressionFactory.GreaterThan( _sqlExpressionFactory.Function( "instr", new[] { source, value }, nullable: true, argumentsPropagateNullability: new[] { true, true }, typeof(int)), _sqlExpressionFactory.Constant(0))); } return(null); }
/// <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> protected virtual void ValidateSharedContainerCompatibility( [NotNull] IReadOnlyList <IEntityType> mappedTypes, [NotNull] string container, [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger) { var discriminatorValues = new Dictionary <object, IEntityType>(); IProperty partitionKey = null; IEntityType firstEntityType = null; foreach (var entityType in mappedTypes) { Check.DebugAssert(entityType.IsDocumentRoot(), "Only document roots expected here."); var partitionKeyPropertyName = entityType.GetPartitionKeyPropertyName(); if (partitionKeyPropertyName != null) { var nextPartitionKeyProperty = entityType.FindProperty(partitionKeyPropertyName); if (partitionKey == null) { if (firstEntityType != null) { throw new InvalidOperationException(CosmosStrings.NoPartitionKey(firstEntityType.DisplayName(), container)); } partitionKey = nextPartitionKeyProperty; } else if (partitionKey.GetJsonPropertyName() != nextPartitionKeyProperty.GetJsonPropertyName()) { throw new InvalidOperationException( CosmosStrings.PartitionKeyStoreNameMismatch( partitionKey.Name, firstEntityType.DisplayName(), partitionKey.GetJsonPropertyName(), nextPartitionKeyProperty.Name, entityType.DisplayName(), nextPartitionKeyProperty.GetJsonPropertyName())); } } else if (partitionKey != null) { throw new InvalidOperationException(CosmosStrings.NoPartitionKey(entityType.DisplayName(), container)); } if (mappedTypes.Count == 1) { break; } if (firstEntityType == null) { firstEntityType = entityType; } if (entityType.ClrType?.IsInstantiable() == true && entityType.GetContainingPropertyName() == null) { if (entityType.GetDiscriminatorProperty() == null) { throw new InvalidOperationException( CosmosStrings.NoDiscriminatorProperty(entityType.DisplayName(), container)); } var discriminatorValue = entityType.GetDiscriminatorValue(); if (discriminatorValue == null) { throw new InvalidOperationException( CosmosStrings.NoDiscriminatorValue(entityType.DisplayName(), container)); } if (discriminatorValues.TryGetValue(discriminatorValue, out var duplicateEntityType)) { throw new InvalidOperationException( CosmosStrings.DuplicateDiscriminatorValue( entityType.DisplayName(), discriminatorValue, duplicateEntityType.DisplayName(), container)); } discriminatorValues[discriminatorValue] = entityType; } } }
/// <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> protected virtual void ValidateKeys( [NotNull] IModel model, [NotNull] IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger) { foreach (var entityType in model.GetEntityTypes()) { var primaryKey = entityType.FindPrimaryKey(); if (primaryKey == null || !entityType.IsDocumentRoot()) { continue; } var idProperty = entityType.GetProperties() .FirstOrDefault(p => p.GetJsonPropertyName() == StoreKeyConvention.IdPropertyJsonName); if (idProperty == null) { throw new InvalidOperationException(CosmosStrings.NoIdProperty(entityType.DisplayName())); } var idType = idProperty.GetTypeMapping().Converter?.ProviderClrType ?? idProperty.ClrType; if (idType != typeof(string)) { throw new InvalidOperationException( CosmosStrings.IdNonStringStoreType( idProperty.Name, entityType.DisplayName(), idType.ShortDisplayName())); } if (!idProperty.IsKey()) { throw new InvalidOperationException(CosmosStrings.NoIdKey(entityType.DisplayName(), idProperty.Name)); } var partitionKeyPropertyName = entityType.GetPartitionKeyPropertyName(); if (partitionKeyPropertyName != null) { var partitionKey = entityType.FindProperty(partitionKeyPropertyName); if (partitionKey == null) { throw new InvalidOperationException( CosmosStrings.PartitionKeyMissingProperty(entityType.DisplayName(), partitionKeyPropertyName)); } var partitionKeyType = partitionKey.GetTypeMapping().Converter?.ProviderClrType ?? partitionKey.ClrType; if (partitionKeyType != typeof(string)) { throw new InvalidOperationException( CosmosStrings.PartitionKeyNonStringStoreType( partitionKeyPropertyName, entityType.DisplayName(), partitionKeyType.ShortDisplayName())); } if (!partitionKey.GetContainingKeys().Any(k => k.Properties.Contains(idProperty))) { throw new InvalidOperationException( CosmosStrings.NoPartitionKeyKey( entityType.DisplayName(), partitionKeyPropertyName, idProperty.Name)); } } } }
public OracleQuerySqlGeneratorSpacer([NotNull] QuerySqlGeneratorDependencies dependencies, [NotNull] SelectExpression selectExpression, string oracleSQLCompatibility, IDiagnosticsLogger <DbLoggerCategory.Query> logger = null) : base(dependencies, selectExpression, oracleSQLCompatibility, logger) { if (!string.IsNullOrEmpty(oracleSQLCompatibility)) { _oracleSQLCompatibility = oracleSQLCompatibility; } if (_oracleSQLCompatibility.StartsWith("11")) { is112SqlCompatibility = true; } m_oracleLogger = logger; }
/// <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 override void Validate(IModel model, IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger) { base.Validate(model, logger); ValidateDefiningQuery(model, logger); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public ForeignKeyIndexConvention([NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> logger) { _logger = logger; }
/// <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 override void Validate(IModel model, IDiagnosticsLogger <DbLoggerCategory.Model.Validation> logger) { base.Validate(model, logger); ValidateSharedContainerCompatibility(model, logger); }
public SqlServerDatabaseModelFactory([NotNull] IDiagnosticsLogger <DbLoggerCategory.Scaffolding> logger) { Check.NotNull(logger, nameof(logger)); _logger = logger; }
/// <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 SqlServerMemoryOptimizedTablesConvention([NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> logger) { Logger = logger; }
public SqlServerStoredProcedureModelFactory(IDiagnosticsLogger <DbLoggerCategory.Scaffolding> logger) { _logger = logger; }
/// <summary> /// 执行并返回一行一列的数据 /// </summary> /// <param name="migrationCommands">迁移命令</param> /// <param name="connection">连接对象</param> /// <param name="logger">日志</param> /// <returns></returns> public object ExecuteScalar( IEnumerable <MigrationCommand> migrationCommands, IRelationalConnection connection, IDiagnosticsLogger <DbLoggerCategory.Database> logger = null) { try { if (Check.IsTraceEnabled(logger?.Logger)) { Trace <DbLoggerCategory.Database> .Write(logger, LogLevel.Trace, OracleTraceTag.Entry, OracleTraceClassName.OracleMigrationCommandExecutor, OracleTraceFuncName.ExecuteScalar); } m_oracleLogger = logger; object result = new object(); Check.NotNull(migrationCommands, nameof(migrationCommands)); Check.NotNull(connection, nameof(connection)); using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { connection.Open(); try { IDbContextTransaction dbContextTransaction = null; try { foreach (MigrationCommand migrationCommand in migrationCommands) { if (dbContextTransaction == null && !migrationCommand.TransactionSuppressed) { dbContextTransaction = connection.BeginTransaction(); } if (dbContextTransaction != null && migrationCommand.TransactionSuppressed) { dbContextTransaction.Commit(); dbContextTransaction.Dispose(); dbContextTransaction = null; } result = ((OracleMigrationCommand)migrationCommand).ExecuteScalar(connection); } dbContextTransaction?.Commit(); } finally { dbContextTransaction?.Dispose(); } } finally { connection.Close(); } } return(result); } catch (Exception ex) { if (Check.IsErrorEnabled(logger?.Logger)) { Trace <DbLoggerCategory.Database> .Write(logger, LogLevel.Error, OracleTraceTag.Error, OracleTraceClassName.OracleMigrationCommandExecutor, OracleTraceFuncName.ExecuteScalar, ex.ToString()); } throw; } finally { if (Check.IsTraceEnabled(logger?.Logger)) { Trace <DbLoggerCategory.Database> .Write(logger, LogLevel.Trace, OracleTraceTag.Exit, OracleTraceClassName.OracleMigrationCommandExecutor, OracleTraceFuncName.ExecuteScalar); } } }
/// <summary> /// Found foreign key on table: {tableName}, id: {id}, principal table: {principalTableName}, delete action: {deleteAction}. /// </summary> public static EventDefinition <string, long, string, string> LogFoundForeignKey([NotNull] IDiagnosticsLogger logger) { var definition = ((Diagnostics.Internal.SqliteLoggingDefinitions)logger.Definitions).LogFoundForeignKey; if (definition == null) { definition = LazyInitializer.EnsureInitialized <EventDefinitionBase>( ref ((Diagnostics.Internal.SqliteLoggingDefinitions)logger.Definitions).LogFoundForeignKey, () => new EventDefinition <string, long, string, string>( logger.Options, SqliteEventId.ForeignKeyFound, LogLevel.Debug, "SqliteEventId.ForeignKeyFound", level => LoggerMessage.Define <string, long, string, string>( level, SqliteEventId.ForeignKeyFound, _resourceManager.GetString("LogFoundForeignKey")))); } return((EventDefinition <string, long, string, string>)definition); }
/// <summary> /// This is internal functionality and not intended for public use. /// </summary> public SpannerLogBridge(IDiagnosticsLogger <TLoggerCategory> efLogger) { _efLogger = efLogger; }
/// <summary> /// For foreign key with identity {id} on table {tableName}, unable to find the column called {principalColumnName} on the foreign key's principal table, {principaltableName}. Skipping foreign key. /// </summary> public static EventDefinition <string, string, string, string> LogPrincipalColumnNotFound([NotNull] IDiagnosticsLogger logger) { var definition = ((Diagnostics.Internal.SqliteLoggingDefinitions)logger.Definitions).LogPrincipalColumnNotFound; if (definition == null) { definition = LazyInitializer.EnsureInitialized <EventDefinitionBase>( ref ((Diagnostics.Internal.SqliteLoggingDefinitions)logger.Definitions).LogPrincipalColumnNotFound, () => new EventDefinition <string, string, string, string>( logger.Options, SqliteEventId.ForeignKeyPrincipalColumnMissingWarning, LogLevel.Warning, "SqliteEventId.ForeignKeyPrincipalColumnMissingWarning", level => LoggerMessage.Define <string, string, string, string>( level, SqliteEventId.ForeignKeyPrincipalColumnMissingWarning, _resourceManager.GetString("LogPrincipalColumnNotFound")))); } return((EventDefinition <string, string, string, string>)definition); }
public DiagnosticsExceptionLogger(IDiagnosticsLogger logger, IJsonConverter converter, IDiagnosticsDumpService dump) { this.logger = logger; this.converter = converter; this.dump = dump; }
public virtual WarningBehavior GetLogBehavior <TLoggerCategory>( [NotNull] IDiagnosticsLogger <TLoggerCategory> logger) where TLoggerCategory : LoggerCategory <TLoggerCategory>, new() => _warningBehavior == WarningBehavior.Log ? logger.Logger.IsEnabled(Level) ? WarningBehavior.Log : WarningBehavior.Ignore : _warningBehavior;
/// <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 RelationalDbFunctionConvention([NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> logger) { Logger = logger; }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public SharedTableConvention([NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> logger) { Logger = logger; }
/// <summary> /// The method called by other methods on this type to execute synchronously. /// </summary> /// <param name="connection"> The connection to use. </param> /// <param name="executeMethod"> The method type. </param> /// <param name="parameterValues"> The parameter values. </param> /// <param name="logger"> The command logger. </param> /// <returns> The result of the execution. </returns> protected virtual object Execute( [NotNull] IRelationalConnection connection, DbCommandMethod executeMethod, [CanBeNull] IReadOnlyDictionary <string, object> parameterValues, [CanBeNull] IDiagnosticsLogger <DbLoggerCategory.Database.Command> logger) { Check.NotNull(connection, nameof(connection)); var dbCommand = CreateCommand(connection, parameterValues); connection.Open(); var commandId = Guid.NewGuid(); var startTime = DateTimeOffset.UtcNow; var stopwatch = Stopwatch.StartNew(); object result; var readerOpen = false; try { switch (executeMethod) { case DbCommandMethod.ExecuteNonQuery: var nonQueryResult = (logger?.CommandNonQueryExecuting( dbCommand, commandId, connection.ConnectionId, startTime: startTime) ?? new InterceptionResult <int>(dbCommand.ExecuteNonQuery())).Result; result = logger?.CommandNonQueryExecuted( dbCommand, commandId, connection.ConnectionId, nonQueryResult, startTime, stopwatch.Elapsed) ?? nonQueryResult; break; case DbCommandMethod.ExecuteScalar: var scalarResult = (logger?.CommandScalarExecuting( dbCommand, commandId, connection.ConnectionId, startTime: startTime) ?? new InterceptionResult <object>(dbCommand.ExecuteScalar())).Result; result = logger?.CommandScalarExecuted( dbCommand, commandId, connection.ConnectionId, scalarResult, startTime, stopwatch.Elapsed) ?? scalarResult; break; case DbCommandMethod.ExecuteReader: var reader = (logger?.CommandReaderExecuting( dbCommand, commandId, connection.ConnectionId, startTime: startTime) ?? new InterceptionResult <DbDataReader>(dbCommand.ExecuteReader())).Result; if (logger != null) { reader = logger?.CommandReaderExecuted( dbCommand, commandId, connection.ConnectionId, reader, startTime, stopwatch.Elapsed); } result = new RelationalDataReader( connection, dbCommand, reader, commandId, logger); readerOpen = true; break; default: throw new NotSupportedException(); } } catch (Exception exception) { logger?.CommandError( dbCommand, executeMethod, commandId, connection.ConnectionId, exception, false, startTime, stopwatch.Elapsed); throw; } finally { if (!readerOpen) { dbCommand.Parameters.Clear(); dbCommand.Dispose(); connection.Close(); } } return(result); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public BaseTypeDiscoveryConvention([NotNull] IDiagnosticsLogger <DbLoggerCategory.Model> logger) : base(logger) { }