Skip to content

Commit 1069897

Browse files
authored
Update to sync to latest EF 9 (#276)
* Small fixes * some smaller fixes to bring up to date to ef 9 * change version to rtm
1 parent bf94f6e commit 1069897

21 files changed

+1301
-211
lines changed

Dependencies.targets

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22
<PropertyGroup>
3-
<DotNetVersion>[9.0.0,9.0.999]</DotNetVersion>
4-
<EFCoreVersion>[9.0.0,9.0.999]</EFCoreVersion>
5-
<MSLibVersion>[9.0.0,9.0.999]</MSLibVersion>
3+
<DotNetVersion>[9.0.4,9.0.999]</DotNetVersion>
4+
<EFCoreVersion>[9.0.4,9.0.999]</EFCoreVersion>
5+
<MSLibVersion>[9.0.4,9.0.999]</MSLibVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
@@ -28,17 +28,17 @@
2828
<PackageReference Update="Microsoft.EntityFrameworkCore.Design" Version="$(EFCoreVersion)" />
2929
<PackageReference Update="Microsoft.EntityFrameworkCore.Relational.Specification.Tests" Version="$(EFCoreVersion)" />
3030
<PackageReference Update="Microsoft.Extensions.Logging.Console" Version="$(MSLibVersion)" />
31-
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.11.1" />
32-
<PackageReference Update="MSTest.TestAdapter" Version="3.6.3" />
33-
<PackageReference Update="MSTest.TestFramework" Version="3.6.3" />
34-
<PackageReference Update="coverlet.collector" Version="6.0.2" />
31+
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.13.0" />
32+
<PackageReference Update="MSTest.TestAdapter" Version="3.8.3" />
33+
<PackageReference Update="MSTest.TestFramework" Version="3.8.3" />
34+
<PackageReference Update="coverlet.collector" Version="6.0.4" />
3535
<PackageReference Update="Newtonsoft.Json" Version="13.0.3" />
3636

3737
<!-- EFCore.Jet.FunctionalTests -->
38-
<PackageReference Update="xunit.core" Version="2.9.2"/>
39-
<PackageReference Update="xunit.assert" Version="2.9.2" />
40-
<PackageReference Update="xunit.runner.visualstudio" Version="2.8.2" />
41-
<PackageReference Update="xunit.runner.console" Version="2.9.2" />
38+
<PackageReference Update="xunit.core" Version="2.9.3"/>
39+
<PackageReference Update="xunit.assert" Version="2.9.3" />
40+
<PackageReference Update="xunit.runner.visualstudio" Version="3.0.2" />
41+
<PackageReference Update="xunit.runner.console" Version="2.9.3" />
4242
<PackageReference Update="Microsoft.Extensions.Configuration.FileExtensions" Version="$(MSLibVersion)" />
4343
<PackageReference Update="NetTopologySuite" Version="2.5.0" />
4444
<PackageReference Update="System.ComponentModel.TypeConverter" Version="4.3.0" />

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Company>CirrusRed</Company>
99
<Copyright>Copyright © 2017-$([System.DateTime]::Now.Year) CirrusRed</Copyright>
1010
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
11-
<LangVersion>12.0</LangVersion>
11+
<LangVersion>13.0</LangVersion>
1212
<Nullable>enable</Nullable>
1313
<DebugType>portable</DebugType>
1414
<IsPackable>False</IsPackable>

Version.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
correctly.
1717
-->
1818
<VersionPrefix>9.0.0</VersionPrefix>
19-
<PreReleaseVersionLabel>beta</PreReleaseVersionLabel>
20-
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
19+
<PreReleaseVersionLabel>rtm</PreReleaseVersionLabel>
20+
<PreReleaseVersionIteration>0</PreReleaseVersionIteration>
2121

2222
<!--
2323
The following properties will automatically be set by CI builds when appropriate:

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"sdk": {
33
"version": "9.0.100",
4-
"allowPrerelease": true,
4+
"allowPrerelease": false,
55
"rollForward": "latestFeature"
66
}
77
}

src/EFCore.Jet.Data/JetCommand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,26 @@ protected virtual int ExecuteNonQueryCore()
284284

285285
if (!CheckExists(InnerCommand.CommandText, out var newCommandText))
286286
return 0;
287+
bool isexistssql = newCommandText != InnerCommand.CommandText && (InnerCommand.CommandText.StartsWith("IF EXISTS",StringComparison.OrdinalIgnoreCase) || InnerCommand.CommandText.StartsWith("IF NOT EXISTS", StringComparison.OrdinalIgnoreCase));
287288

288289
InnerCommand.CommandText = newCommandText;
289290

290291
InlineTopParameters();
291292
FixParameters();
292293

293-
_connection.RowCount = InnerCommand.ExecuteNonQuery();
294+
try
295+
{
296+
_connection.RowCount = InnerCommand.ExecuteNonQuery();
297+
}
298+
catch (DbException e)
299+
{
300+
if (!e.Message.Contains("already exists") || !isexistssql)
301+
{
302+
throw;
303+
}
304+
305+
return 0;
306+
}
294307

295308
// For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command.
296309
// For all other types of statements, the return value is -1. If a rollback occurs, the return value is also -1.

src/EFCore.Jet/Migrations/Internal/JetHistoryRepository.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,59 @@ public override string GetEndIfScript()
291291
{
292292
throw new NotSupportedException(JetStrings.MigrationScriptGenerationNotSupported);
293293
}
294+
295+
public override IReadOnlyList<HistoryRow> GetAppliedMigrations()
296+
{
297+
var rows = new List<HistoryRow>();
298+
//Note the exists check opens a new connection with adox/dao. If doing within a transaction it wont find the table until the transaction is committed. Just read anyway
299+
//No op if the table does not exist
300+
//if (Exists())
301+
{
302+
var command = Dependencies.RawSqlCommandBuilder.Build(GetAppliedMigrationsSql);
303+
304+
using var reader = command.ExecuteReader(
305+
new RelationalCommandParameterObject(
306+
Dependencies.Connection,
307+
null,
308+
null,
309+
Dependencies.CurrentContext.Context,
310+
Dependencies.CommandLogger, CommandSource.Migrations));
311+
while (reader.Read())
312+
{
313+
rows.Add(new HistoryRow(reader.DbDataReader.GetString(0), reader.DbDataReader.GetString(1)));
314+
}
315+
}
316+
317+
return rows;
318+
}
319+
320+
public override async Task<IReadOnlyList<HistoryRow>> GetAppliedMigrationsAsync(CancellationToken cancellationToken = new CancellationToken())
321+
{
322+
var rows = new List<HistoryRow>();
323+
//Note the exists check opens a new connection with adox/dao. If doing within a transaction it wont find the table until the transaction is committed. Just read anyway
324+
//No op if the table does not exist
325+
//if (await ExistsAsync(cancellationToken).ConfigureAwait(false))
326+
{
327+
var command = Dependencies.RawSqlCommandBuilder.Build(GetAppliedMigrationsSql);
328+
329+
var reader = await command.ExecuteReaderAsync(
330+
new RelationalCommandParameterObject(
331+
Dependencies.Connection,
332+
null,
333+
null,
334+
Dependencies.CurrentContext.Context,
335+
Dependencies.CommandLogger, CommandSource.Migrations),
336+
cancellationToken).ConfigureAwait(false);
337+
338+
await using var _ = reader.ConfigureAwait(false);
339+
340+
while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
341+
{
342+
rows.Add(new HistoryRow(reader.DbDataReader.GetString(0), reader.DbDataReader.GetString(1)));
343+
}
344+
}
345+
346+
return rows;
347+
}
294348
}
295349
}

src/EFCore.Jet/Migrations/Internal/JetMigrationCommandExecutor.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using EntityFrameworkCore.Jet.Data.JetStoreSchemaDefinition;
1+
using EntityFrameworkCore.Jet.Data;
2+
using EntityFrameworkCore.Jet.Data.JetStoreSchemaDefinition;
23
using Microsoft.EntityFrameworkCore.Migrations.Internal;
34

45
namespace EntityFrameworkCore.Jet.Migrations.Internal
@@ -19,12 +20,18 @@ public override int ExecuteNonQuery(
1920
System.Data.IsolationLevel? isolationLevel = null)
2021
{
2122
var batches = CreateMigrationBatches(migrationCommands);
23+
int output = 0;
24+
2225
foreach (var batch in batches)
2326
{
24-
base.ExecuteNonQuery(batch, connection, executionState, true, isolationLevel);
27+
output += base.ExecuteNonQuery(batch.Item1, connection, executionState, true, isolationLevel);
28+
if (batch.Item2) Thread.Sleep(4000);//Wait for adox/dao to complete
2529
}
26-
27-
return -1;
30+
if (connection.CurrentTransaction != null)
31+
{
32+
connection.CurrentTransaction.Commit();
33+
}
34+
return output;
2835
}
2936

3037
public override async Task<int> ExecuteNonQueryAsync(
@@ -38,27 +45,31 @@ public override async Task<int> ExecuteNonQueryAsync(
3845
var batches = CreateMigrationBatches(migrationCommands);
3946
foreach (var batch in batches)
4047
{
41-
await base.ExecuteNonQueryAsync(batch, connection, executionState, true, isolationLevel, cancellationToken);
48+
await base.ExecuteNonQueryAsync(batch.Item1, connection, executionState, true, isolationLevel, cancellationToken);
49+
if (batch.Item2) Thread.Sleep(4000);
50+
}
51+
if (connection.CurrentTransaction != null)
52+
{
53+
await connection.CurrentTransaction.CommitAsync(cancellationToken);
4254
}
43-
4455
return -1;
4556
}
4657

47-
List<IReadOnlyList<MigrationCommand>> CreateMigrationBatches(IReadOnlyList<MigrationCommand> migrationCommands)
58+
List<(IReadOnlyList<MigrationCommand>,bool)> CreateMigrationBatches(IReadOnlyList<MigrationCommand> migrationCommands)
4859
{
4960
//create new batch if JetSchemaOperationsHandling.IsDatabaseOperation is true otherwise had to current batch
50-
var migrationBatches = new List<IReadOnlyList<MigrationCommand>>();
61+
var migrationBatches = new List<(IReadOnlyList<MigrationCommand>, bool)>();
5162
var currentBatch = new List<MigrationCommand>();
5263
foreach (var migrationCommand in migrationCommands)
5364
{
5465
if (JetSchemaOperationsHandling.IsDatabaseOperation(migrationCommand.CommandText))
5566
{
5667
if (currentBatch.Count != 0)
5768
{
58-
migrationBatches.Add(currentBatch);
69+
migrationBatches.Add((currentBatch,false));
5970
currentBatch = [];
6071
}
61-
migrationBatches.Add([migrationCommand]);
72+
migrationBatches.Add(([migrationCommand],true));
6273
}
6374
else
6475
{
@@ -67,7 +78,7 @@ List<IReadOnlyList<MigrationCommand>> CreateMigrationBatches(IReadOnlyList<Migra
6778
}
6879
if (currentBatch.Count != 0)
6980
{
70-
migrationBatches.Add(currentBatch);
81+
migrationBatches.Add((currentBatch,false));
7182
}
7283
return migrationBatches;
7384
}

src/EFCore.Jet/Storage/Internal/JetDateOnlyTypeMapping.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,9 @@ protected virtual DateTime ConvertToDateTimeCompatibleValue(object value)
7373

7474
private static DateTime CheckDateTimeValue(DateTime dateTime)
7575
{
76-
if (dateTime < JetConfiguration.TimeSpanOffset)
76+
if (dateTime != default && dateTime < new DateTime(100,1,1))
7777
{
78-
if (dateTime != default)
79-
{
80-
throw new InvalidOperationException($"The {nameof(DateTime)} value '{dateTime}' is smaller than the minimum supported value of '{JetConfiguration.TimeSpanOffset}'.");
81-
}
82-
83-
dateTime = JetConfiguration.TimeSpanOffset;
78+
throw new InvalidOperationException($"The {nameof(DateTime)} value '{dateTime}' is smaller than the minimum supported value of '{new DateTime(100, 1, 1)}'.");
8479
}
8580

8681
return dateTime;

test/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<PropertyGroup>
55
<NoWarn>$(NoWarn);CA1707;1591;xUnit1000;xUnit1003;xUnit1004;xUnit1010;xUnit1013;xUnit1026;xUnit2013;xUnit1024;NU1903;EF1001</NoWarn>
6-
<LangVersion>preview</LangVersion>
6+
<LangVersion>13.0</LangVersion>
77
<DefaultNetCoreTargetFramework>net9.0</DefaultNetCoreTargetFramework>
88
<!-- TODO: Change to "'$(FixedTestOrder)' != 'true'" once test suite is stable. -->
99
<DefineConstants Condition="'$(FixedTestOrder)' != 'false'">$(DefineConstants);FIXED_TEST_ORDER</DefineConstants>

0 commit comments

Comments
 (0)