Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync to EF RC1 #264

Merged
merged 8 commits into from
Sep 27, 2024
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
14 changes: 7 additions & 7 deletions Dependencies.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<DotNetVersion>[9.0.0-preview.7.24405.4,9.0.999]</DotNetVersion>
<EFCoreVersion>[9.0.0-preview.7.24405.3,9.0.999]</EFCoreVersion>
<MSLibVersion>[9.0.0-preview.7.24405.7,9.0.999]</MSLibVersion>
<DotNetVersion>[9.0.100-rc.1.24452.12,9.0.999]</DotNetVersion>
<EFCoreVersion>[9.0.0-rc.1.24451.1,9.0.999]</EFCoreVersion>
<MSLibVersion>[9.0.0-rc.1.24431.7,9.0.999]</MSLibVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,9 +28,9 @@
<PackageReference Update="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreVersion)" />
<PackageReference Update="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="$(EFCoreVersion)" /> <!-- Should be same as efcoreversion. preview6 was broken and published separately -->
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="$(MSLibVersion)" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.11.0-release-24373-02" />
<PackageReference Update="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Update="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Update="MSTest.TestAdapter" Version="3.6.0" />
<PackageReference Update="MSTest.TestFramework" Version="3.6.0" />
<PackageReference Update="coverlet.collector" Version="6.0.2" />
<PackageReference Update="Newtonsoft.Json" Version="13.0.3" />

Expand All @@ -45,6 +45,6 @@

<!-- EFCore.Jet.Tests -->
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="$(MSLibVersion)" />
<PackageReference Update="Moq" Version="4.20.70" />
<PackageReference Update="Moq" Version="4.20.72" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.100-preview.7.24407.12",
"version": "9.0.100-rc.1.24452.12",
"allowPrerelease": true,
"rollForward": "latestFeature"
}
Expand Down
39 changes: 4 additions & 35 deletions src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public override string GetDeleteScript(string migrationId)
.ToString();
}

public override IDisposable GetDatabaseLock(TimeSpan timeout)
public override IDisposable GetDatabaseLock()
{
if (!InterpretExistsResult(Dependencies.RawSqlCommandBuilder.Build(CreateExistsSql(LockTableName))
.ExecuteScalar(CreateRelationalCommandParameters())))
Expand All @@ -144,8 +144,7 @@ public override IDisposable GetDatabaseLock(TimeSpan timeout)
}

var retryDelay = _retryDelay;
var startTime = DateTimeOffset.UtcNow;
while (DateTimeOffset.UtcNow - startTime < timeout)
while (true)
{
var dbLock = CreateMigrationDatabaseLock();
int? insertCount = 0;
Expand All @@ -164,17 +163,6 @@ public override IDisposable GetDatabaseLock(TimeSpan timeout)
return dbLock;
}

using var reader = CreateGetLockCommand().ExecuteReader(CreateRelationalCommandParameters());
if (reader.Read())
{
var timestamp = reader.DbDataReader.GetFieldValue<DateTimeOffset>(1);
if (DateTimeOffset.UtcNow - timestamp > timeout)
{
var id = reader.DbDataReader.GetFieldValue<int>(0);
CreateDeleteLockCommand(id).ExecuteNonQuery(CreateRelationalCommandParameters());
}
}

Thread.Sleep(retryDelay);
if (retryDelay < TimeSpan.FromMinutes(1))
{
Expand All @@ -185,7 +173,7 @@ public override IDisposable GetDatabaseLock(TimeSpan timeout)
throw new TimeoutException();
}

public override async Task<IAsyncDisposable> GetDatabaseLockAsync(TimeSpan timeout, CancellationToken cancellationToken = new CancellationToken())
public override async Task<IAsyncDisposable> GetDatabaseLockAsync(CancellationToken cancellationToken = new CancellationToken())
{
if (!InterpretExistsResult(await Dependencies.RawSqlCommandBuilder.Build(CreateExistsSql(LockTableName))
.ExecuteScalarAsync(CreateRelationalCommandParameters(), cancellationToken).ConfigureAwait(false)))
Expand All @@ -204,8 +192,7 @@ await CreateLockTableCommand()
}

var retryDelay = _retryDelay;
var startTime = DateTimeOffset.UtcNow;
while (DateTimeOffset.UtcNow - startTime < timeout)
while (true)
{
var dbLock = CreateMigrationDatabaseLock();
int? insertCount = 0;
Expand All @@ -225,19 +212,6 @@ await CreateLockTableCommand()
return dbLock;
}

using var reader = await CreateGetLockCommand().ExecuteReaderAsync(CreateRelationalCommandParameters(), cancellationToken)
.ConfigureAwait(false);
if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
{
var timestamp = await reader.DbDataReader.GetFieldValueAsync<DateTimeOffset>(1).ConfigureAwait(false);
if (DateTimeOffset.UtcNow - timestamp > timeout)
{
var id = await reader.DbDataReader.GetFieldValueAsync<int>(0).ConfigureAwait(false);
await CreateDeleteLockCommand(id).ExecuteNonQueryAsync(CreateRelationalCommandParameters(), cancellationToken)
.ConfigureAwait(false);
}
}

await Task.Delay(_retryDelay, cancellationToken).ConfigureAwait(true);
if (retryDelay < TimeSpan.FromMinutes(1))
{
Expand Down Expand Up @@ -266,11 +240,6 @@ private IRelationalCommand CreateInsertLockCommand(DateTimeOffset timestamp)
""");
}

private IRelationalCommand CreateGetLockCommand()
=> Dependencies.RawSqlCommandBuilder.Build($"""
SELECT TOP 1 `Id`, `Timestamp` FROM `{LockTableName}`;
""");

private IRelationalCommand CreateDeleteLockCommand(int? id = null)
{
var sql = $"""
Expand Down
19 changes: 15 additions & 4 deletions src/EFCore.Jet/Query/Internal/JetLocateScalarSubqueryVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,22 @@ protected override Expression VisitJsonScalar(JsonScalarExpression jsonScalarExp

protected override Expression VisitValues(ValuesExpression valuesExpression)
{
var rowValues = new RowValueExpression[valuesExpression.RowValues.Count];
for (var i = 0; i < rowValues.Length; i++)
switch (valuesExpression)
{
rowValues[i] = (RowValueExpression)Visit(valuesExpression.RowValues[i]);
case { RowValues: not null }:
var rowValues = new RowValueExpression[valuesExpression.RowValues!.Count];
for (var i = 0; i < rowValues.Length; i++)
{
rowValues[i] = (RowValueExpression)Visit(valuesExpression.RowValues[i]);
}
return valuesExpression.Update(rowValues);

case { ValuesParameter: not null }:
var valuesParameter = (SqlParameterExpression)Visit(valuesExpression.ValuesParameter);
return valuesExpression.Update(valuesParameter);

default:
throw new UnreachableException();
}
return valuesExpression.Update(rowValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class JetParameterBasedSqlProcessor : RelationalParameterBasedSqlProcesso
/// </summary>
public JetParameterBasedSqlProcessor(
RelationalParameterBasedSqlProcessorDependencies dependencies,
bool useRelationalNulls)
: base(dependencies, useRelationalNulls)
RelationalParameterBasedSqlProcessorParameters parameters)
: base(dependencies, parameters)
{
}

Expand Down Expand Up @@ -64,7 +64,7 @@ protected override Expression ProcessSqlNullability(
Check.NotNull(selectExpression, nameof(selectExpression));
Check.NotNull(parametersValues, nameof(parametersValues));

return new JetSqlNullabilityProcessor(Dependencies, UseRelationalNulls).Process(
return new JetSqlNullabilityProcessor(Dependencies, Parameters).Process(
selectExpression, parametersValues, out canCache);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public JetParameterBasedSqlProcessorFactory(RelationalParameterBasedSqlProcessor
/// 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 RelationalParameterBasedSqlProcessor Create(bool useRelationalNulls)
=> new JetParameterBasedSqlProcessor(Dependencies, useRelationalNulls);
public RelationalParameterBasedSqlProcessor Create(RelationalParameterBasedSqlProcessorParameters parameters)
=> new JetParameterBasedSqlProcessor(Dependencies, parameters);
}
4 changes: 2 additions & 2 deletions src/EFCore.Jet/Query/Internal/JetSqlNullabilityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class JetSqlNullabilityProcessor : SqlNullabilityProcessor
/// </summary>
public JetSqlNullabilityProcessor(
RelationalParameterBasedSqlProcessorDependencies dependencies,
bool useRelationalNulls)
: base(dependencies, useRelationalNulls)
RelationalParameterBasedSqlProcessorParameters parameters)
: base(dependencies, parameters)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using EntityFrameworkCore.Jet.Utilities;
using Microsoft.EntityFrameworkCore.Diagnostics;
Expand Down Expand Up @@ -648,14 +649,24 @@ protected override Expression VisitValues(ValuesExpression valuesExpression)
{
var parentSearchCondition = _isSearchCondition;
_isSearchCondition = false;

var rowValues = new RowValueExpression[valuesExpression.RowValues.Count];
for (var i = 0; i < rowValues.Length; i++)
switch (valuesExpression)
{
rowValues[i] = (RowValueExpression)Visit(valuesExpression.RowValues[i]);
}
case { RowValues: not null }:
var rowValues = new RowValueExpression[valuesExpression.RowValues!.Count];
for (var i = 0; i < rowValues.Length; i++)
{
rowValues[i] = (RowValueExpression)Visit(valuesExpression.RowValues[i]);
}
_isSearchCondition = parentSearchCondition;
return valuesExpression.Update(rowValues);

_isSearchCondition = parentSearchCondition;
return valuesExpression.Update(rowValues);
case { ValuesParameter: not null }:
var valuesParameter = (SqlParameterExpression)Visit(valuesExpression.ValuesParameter);
_isSearchCondition = parentSearchCondition;
return valuesExpression.Update(valuesParameter);

default:
throw new UnreachableException();
}
}
}
2 changes: 1 addition & 1 deletion src/EFCore.Jet/Query/Sql/Internal/JetQuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ protected override Expression VisitValues(ValuesExpression valuesExpression)
/// </summary>
protected override void GenerateValues(ValuesExpression valuesExpression)
{
if (valuesExpression.RowValues.Count == 0)
if (valuesExpression.RowValues is null || valuesExpression.RowValues.Count == 0)
{
throw new InvalidOperationException(RelationalStrings.EmptyCollectionNotSupportedAsInlineQueryRoot);
}
Expand Down
Loading