Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/EFCore.Jet.Data/ConnectionPooling/ConnectionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@

namespace EntityFrameworkCore.Jet.Data.ConnectionPooling
{
class ConnectionSet : IDisposable
class ConnectionSet(string connectionString) : IDisposable
{
public ConnectionSet(string connectionString)
{
ConnectionString = connectionString;
_connections = new DbConnection[10];
ConnectionCount = 0;
}

public string ConnectionString { get; }
public string ConnectionString { get; } = connectionString;

private DbConnection[] _connections;
public int ConnectionCount { get; private set; }
private DbConnection[] _connections = new DbConnection[10];
public int ConnectionCount { get; private set; } = 0;

public void AddConnection(DbConnection connection)
{
Expand Down
12 changes: 3 additions & 9 deletions src/EFCore.Jet.Data/PreciseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@

namespace EntityFrameworkCore.Jet.Data
{
public class PreciseSchema : SchemaProvider
public class PreciseSchema(JetConnection connection, bool readOnly) : SchemaProvider
{
private readonly Lazy<AdoxSchema> _adoxSchema;
private readonly Lazy<DaoSchema> _daoSchema;

public PreciseSchema(JetConnection connection, bool readOnly)
{
_adoxSchema = new Lazy<AdoxSchema>(() => new AdoxSchema(connection, true, readOnly), false);
_daoSchema = new Lazy<DaoSchema>(() => new DaoSchema(connection, true, readOnly), false);
}
private readonly Lazy<AdoxSchema> _adoxSchema = new(() => new AdoxSchema(connection, true, readOnly), false);
private readonly Lazy<DaoSchema> _daoSchema = new(() => new DaoSchema(connection, true, readOnly), false);

public override void EnsureDualTable()
=> _adoxSchema.Value.EnsureDualTable(); // prefer ADOX, but DAO works too (but less precise)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,11 @@ public virtual JetOptionsExtension WithUseShortTextForSystemString(bool enabled)
public override void ApplyServices(IServiceCollection services)
=> services.AddEntityFrameworkJet();

private sealed class ExtensionInfo : RelationalExtensionInfo
private sealed class ExtensionInfo(IDbContextOptionsExtension extension) : RelationalExtensionInfo(extension)
{
private int? _serviceProviderHash;
private string? _logFragment;

public ExtensionInfo(IDbContextOptionsExtension extension)
: base(extension)
{
}

private new JetOptionsExtension Extension
=> (JetOptionsExtension)base.Extension;

Expand Down
18 changes: 6 additions & 12 deletions src/EFCore.Jet/Metadata/Conventions/JetConventionSetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,19 @@
// ReSharper disable once CheckNamespace
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
public class JetConventionSetBuilder : RelationalConventionSetBuilder
public class JetConventionSetBuilder(
[NotNull] ProviderConventionSetBuilderDependencies dependencies,
[NotNull] RelationalConventionSetBuilderDependencies relationalDependencies,
ISqlGenerationHelper sqlGenerationHelper)
: RelationalConventionSetBuilder(dependencies, relationalDependencies)
{
private readonly ISqlGenerationHelper _sqlGenerationHelper;
public JetConventionSetBuilder(
[NotNull] ProviderConventionSetBuilderDependencies dependencies,
[NotNull] RelationalConventionSetBuilderDependencies relationalDependencies,
ISqlGenerationHelper sqlGenerationHelper)
: base(dependencies, relationalDependencies)
{
_sqlGenerationHelper = sqlGenerationHelper;
}

public override ConventionSet CreateConventionSet()
{
var conventionSet = base.CreateConventionSet();

conventionSet.Add(new JetValueGenerationStrategyConvention(Dependencies, RelationalDependencies));
conventionSet.Add(new RelationalMaxIdentifierLengthConvention(64, Dependencies, RelationalDependencies));
conventionSet.Add(new JetIndexConvention(Dependencies, RelationalDependencies, _sqlGenerationHelper));
conventionSet.Add(new JetIndexConvention(Dependencies, RelationalDependencies, sqlGenerationHelper));

conventionSet.Replace<CascadeDeleteConvention>(
new JetOnDeleteConvention(Dependencies, RelationalDependencies));
Expand Down
19 changes: 7 additions & 12 deletions src/EFCore.Jet/Metadata/Conventions/JetOnDeleteConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,17 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions;
/// A convention that configures the OnDelete behavior for foreign keys on the join entity type for
/// self-referencing skip navigations
/// </summary>
public class JetOnDeleteConvention : CascadeDeleteConvention,
ISkipNavigationForeignKeyChangedConvention,
IEntityTypeAnnotationChangedConvention
public class JetOnDeleteConvention(
ProviderConventionSetBuilderDependencies dependencies,
RelationalConventionSetBuilderDependencies relationalDependencies)
: CascadeDeleteConvention(dependencies),
ISkipNavigationForeignKeyChangedConvention,
IEntityTypeAnnotationChangedConvention
{
public JetOnDeleteConvention(
ProviderConventionSetBuilderDependencies dependencies,
RelationalConventionSetBuilderDependencies relationalDependencies)
: base(dependencies)
{
RelationalDependencies = relationalDependencies;
}

/// <summary>
/// Relational provider-specific dependencies for this service.
/// </summary>
protected virtual RelationalConventionSetBuilderDependencies RelationalDependencies { get; }
protected virtual RelationalConventionSetBuilderDependencies RelationalDependencies { get; } = relationalDependencies;

/// <inheritdoc />
public virtual void ProcessSkipNavigationForeignKeyChanged(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetConvertTranslator : IMethodCallTranslator
public class JetConvertTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private readonly JetSqlExpressionFactory _sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

// The value here is actually never used.
private static readonly Dictionary<string, string> _functionName = new Dictionary<string, string>
Expand Down Expand Up @@ -61,9 +61,6 @@ private static readonly IEnumerable<MethodInfo> _supportedMethods
.ParameterType)))
.ToList();

public JetConvertTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;


public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
{
public class JetDateDiffFunctionsTranslator : IMethodCallTranslator
public class JetDateDiffFunctionsTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private readonly Dictionary<MethodInfo, string> _methodInfoDateDiffMapping
= new Dictionary<MethodInfo, string>
Expand Down Expand Up @@ -197,14 +197,6 @@ private readonly Dictionary<MethodInfo, string> _methodInfoDateDiffMapping
},
};

private readonly ISqlExpressionFactory _sqlExpressionFactory;

public JetDateDiffFunctionsTranslator(
ISqlExpressionFactory sqlExpressionFactory)
{
_sqlExpressionFactory = sqlExpressionFactory;
}

public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (_methodInfoDateDiffMapping.TryGetValue(method, out var datePart))
Expand All @@ -213,12 +205,12 @@ public JetDateDiffFunctionsTranslator(
var endDate = arguments[2];
var typeMapping = ExpressionExtensions.InferTypeMapping(startDate, endDate);

startDate = _sqlExpressionFactory.ApplyTypeMapping(startDate, typeMapping);
endDate = _sqlExpressionFactory.ApplyTypeMapping(endDate, typeMapping);
startDate = sqlExpressionFactory.ApplyTypeMapping(startDate, typeMapping);
endDate = sqlExpressionFactory.ApplyTypeMapping(endDate, typeMapping);

return _sqlExpressionFactory.Function(
return sqlExpressionFactory.Function(
"DATEDIFF",
new[] { _sqlExpressionFactory.Constant(datePart), startDate, endDate },
new[] { sqlExpressionFactory.Constant(datePart), startDate, endDate },
false,
new[] {false, false, false},
typeof(int));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetDateTimeMemberTranslator : IMemberTranslator
public class JetDateTimeMemberTranslator(
ISqlExpressionFactory sqlExpressionFactory,
IRelationalTypeMappingSource typeMappingSource)
: IMemberTranslator
{
private static readonly Dictionary<string, string> DatePartMapping
= new()
Expand All @@ -32,16 +35,8 @@ private static readonly Dictionary<string, string> DatePartMapping
//{ nameof(DateTime.Millisecond), "millisecond" }
};

private readonly JetSqlExpressionFactory _sqlExpressionFactory;
private readonly IRelationalTypeMappingSource _typeMappingSource;

public JetDateTimeMemberTranslator(
ISqlExpressionFactory sqlExpressionFactory,
IRelationalTypeMappingSource typeMappingSource)
{
_sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;
_typeMappingSource = typeMappingSource;
}
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;
private readonly IRelationalTypeMappingSource _typeMappingSource = typeMappingSource;

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetDateTimeMethodTranslator : IMethodCallTranslator
public class JetDateTimeMethodTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private readonly JetSqlExpressionFactory _sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

private readonly Dictionary<MethodInfo, string> _methodInfoDatePartMapping = new Dictionary<MethodInfo, string>
{
Expand All @@ -44,9 +44,6 @@ public class JetDateTimeMethodTranslator : IMethodCallTranslator
{ typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.ToUnixTimeMilliseconds), Type.EmptyTypes)!, "millisecond" }
};

public JetDateTimeMethodTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
if (_methodInfoDatePartMapping.TryGetValue(method, out var datePart) && instance != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@

namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
{
public class JetIsDateFunctionTranslator : IMethodCallTranslator
public class JetIsDateFunctionTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private readonly ISqlExpressionFactory _sqlExpressionFactory;

private static readonly MethodInfo _methodInfo = typeof(JetDbFunctionsExtensions)
.GetRuntimeMethod(nameof(JetDbFunctionsExtensions.IsDate), new[] { typeof(DbFunctions), typeof(string) })!;

public JetIsDateFunctionTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = sqlExpressionFactory;

public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
return _methodInfo.Equals(method)
? _sqlExpressionFactory.Convert(
_sqlExpressionFactory.Function(
? sqlExpressionFactory.Convert(
sqlExpressionFactory.Function(
"ISDATE",
new[] { arguments[1] },
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetMathTranslator : IMethodCallTranslator
public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private readonly JetSqlExpressionFactory _sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

private static readonly Dictionary<MethodInfo, string> _supportedMethodTranslationsDirect = new Dictionary<MethodInfo, string>
{
Expand Down Expand Up @@ -96,9 +96,6 @@ public class JetMathTranslator : IMethodCallTranslator
typeof(MathF).GetRuntimeMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!
};

public JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetNewGuidTranslator : IMethodCallTranslator
public class JetNewGuidTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private static readonly MethodInfo _methodInfo = typeof(Guid).GetRuntimeMethod(nameof(Guid.NewGuid), Array.Empty<Type>())!;
private readonly JetSqlExpressionFactory _sqlExpressionFactory;

public JetNewGuidTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetObjectToStringTranslator : IMethodCallTranslator
public class JetObjectToStringTranslator(SqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private readonly JetSqlExpressionFactory _sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

private const int DefaultLength = 100;

Expand All @@ -43,9 +43,6 @@ private static readonly Dictionary<Type, string> TypeMapping
{ typeof(byte[]), $"varchar({DefaultLength})" }
};

public JetObjectToStringTranslator(SqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

public virtual SqlExpression? Translate(
SqlExpression? instance,
MethodInfo method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetRandomTranslator : IMethodCallTranslator
public class JetRandomTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMethodCallTranslator
{
private static readonly MethodInfo[] _methodInfo =
{
Expand All @@ -28,10 +28,7 @@ public class JetRandomTranslator : IMethodCallTranslator
typeof(DbFunctions)
})!
};
private readonly JetSqlExpressionFactory _sqlExpressionFactory;

public JetRandomTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

public SqlExpression? Translate(SqlExpression? instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments, IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal
/// 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 class JetStringMemberTranslator : IMemberTranslator
public class JetStringMemberTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMemberTranslator
{
private readonly JetSqlExpressionFactory _sqlExpressionFactory;

public JetStringMemberTranslator(ISqlExpressionFactory sqlExpressionFactory)
=> _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;
private readonly JetSqlExpressionFactory _sqlExpressionFactory = (JetSqlExpressionFactory)sqlExpressionFactory;

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
Expand Down
Loading