Skip to content

Commit

Permalink
update to EF Core 9 where it is possible
Browse files Browse the repository at this point in the history
  • Loading branch information
win7user10 committed Nov 19, 2024
1 parent a0b3e30 commit 019f2ca
Show file tree
Hide file tree
Showing 38 changed files with 247 additions and 183 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
major_version=${GITHUB_REF:10:1} \
&& echo "MAJOR_VERSION=${major_version}" >> $GITHUB_ENV \
&& [[ $major_version = 5 ]] && echo "PROJECT_TARGET=netstandard2.1" >> $GITHUB_ENV || [[ $major_version = 6 ]] && echo "PROJECT_TARGET=net6.0" >> $GITHUB_ENV || echo "PROJECT_TARGET=net8.0" >> $GITHUB_ENV \
&& [[ $major_version = 5 ]] && echo "PROJECT_TARGET=netstandard2.1" >> $GITHUB_ENV || [[ $major_version = 6 ]] && echo "PROJECT_TARGET=net6.0" >> $GITHUB_ENV || [[ $major_version = 8 ]] && echo "PROJECT_TARGET=net8.0" >> $GITHUB_ENV || echo "PROJECT_TARGET=net9.0" >> $GITHUB_ENV \
&& echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Setup .NET5 environment
Expand All @@ -34,14 +34,20 @@ jobs:
with:
dotnet-version: '6.x.x'

- name: Setup .NET8 environment
- name: Setup .NET9 environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.x.x'


- name: Setup .NET8 environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: '9.x.x'

- name: Build project
run: |
for p in $(find ./src -name *.csproj); do dotnet build $p --framework ${{env.PROJECT_TARGET}} --configuration Release; done
for p in $(find ./src -name *.csproj -not -name *MySql.csproj); do dotnet build $p --framework ${{env.PROJECT_TARGET}} --configuration Release; done
- name: Generate a NuGet package
run: dotnet pack -p:TargetFrameworks=${{env.PROJECT_TARGET}} -p:PackageVersion=${{env.RELEASE_VERSION}} --no-build -c Release -o .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<Description>Common classes EfCoreTriggers packages.</Description>
<RepositoryUrl>https://github.com/win7user10/Laraue.EfCoreTriggers</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -23,19 +23,27 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.20">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.20" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.11">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.11" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ public class MigrationsModelDiffer : Microsoft.EntityFrameworkCore.Migrations.In
/// <summary>
/// Initializes a new instance of <see cref="MigrationsModelDiffer"/>.
/// </summary>
/// <param name="typeMappingSource"></param>
/// <param name="migrationsAnnotations"></param>
/// <param name="changeDetector"></param>
/// <param name="updateAdapterFactory"></param>
/// <param name="triggerModelDiffer"></param>
/// <param name="commandBatchPreparerDependencies"></param>
#if NET6_0_OR_GREATER
#if NET9_0_OR_GREATER
public MigrationsModelDiffer(
IRelationalTypeMappingSource typeMappingSource,
IMigrationsAnnotationProvider migrationsAnnotationProvider,
IRelationalAnnotationProvider relationalAnnotationProvider,
IRowIdentityMapFactory rowIdentityMapFactory,
CommandBatchPreparerDependencies commandBatchPreparerDependencies,
ITriggerModelDiffer triggerModelDiffer)
: base(
typeMappingSource,
migrationsAnnotationProvider,
relationalAnnotationProvider,
rowIdentityMapFactory,
commandBatchPreparerDependencies)
{
_triggerModelDiffer = triggerModelDiffer;
}
#elif NET6_0_OR_GREATER
public MigrationsModelDiffer(
IRelationalTypeMappingSource typeMappingSource,
IMigrationsAnnotationProvider migrationsAnnotationProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static void ConvertTriggerAnnotationsToSql(this ITriggerVisitor triggerVi
{
foreach (var entityType in model?.GetEntityTypes() ?? Enumerable.Empty<IEntityType>())
{
var annotations = (SortedDictionary<string, Annotation>?) AnnotationsField.GetValue(entityType);
var annotations = (IDictionary<string, Annotation>?) AnnotationsField.GetValue(entityType);

if (annotations is null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<Description>Generating native PostgreSql triggers through migrations using EFCore entity builder.</Description>
<RepositoryUrl>https://github.com/win7user10/Laraue.EfCoreTriggers</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<Description>Generating native SqlLite triggers through migrations using EFCore entity builder.</Description>
<RepositoryUrl>https://github.com/win7user10/Laraue.EfCoreTriggers</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<Description>Generating native SqlServer triggers through migrations using EFCore entity builder.</Description>
<RepositoryUrl>https://github.com/win7user10/Laraue.EfCoreTriggers</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
1 change: 0 additions & 1 deletion tests/Laraue.EfCoreTriggers.MySqlTests/ContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public DbContextOptions<TContext> CreateDbContextOptions()
.UseMySql("server=localhost;user=root;password=mysql;database=efcoretriggers;", new MySqlServerVersion(new Version(8, 0, 22)),
x => x
.MigrationsAssembly(typeof(ContextFactory).Assembly.FullName))
.UseSnakeCaseNamingConvention()
.UseMySqlTriggers()
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.2.ci.20231014172607" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public MySqlUnitDateTimeFunctionsTests()
}

protected override string ExceptedDateTimeUtcNowSql
=> "INSERT INTO `destination_entities` (`date_time_value`) SELECT UTC_TIMESTAMP();";
=> "INSERT INTO `DestinationEntities` (`DateTimeValue`) SELECT UTC_TIMESTAMP();";

protected override string ExceptedDateTimeNowSql
=> "INSERT INTO `destination_entities` (`date_time_value`) SELECT LOCALTIME();";
=> "INSERT INTO `DestinationEntities` (`DateTimeValue`) SELECT LOCALTIME();";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ public MySqlUnitMathFunctionsTests() : base(
{
}

protected override string ExceptedAbsSql => "INSERT INTO `destination_entities` (`decimal_value`) SELECT ABS(NEW.`decimal_value`);";
protected override string ExceptedAbsSql => "INSERT INTO `DestinationEntities` (`DecimalValue`) SELECT ABS(NEW.`DecimalValue`);";

protected override string ExceptedAcosSql => "INSERT INTO `destination_entities` (`double_value`) SELECT ACOS(NEW.`double_value`);";
protected override string ExceptedAcosSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT ACOS(NEW.`DoubleValue`);";

protected override string ExceptedAsinSql => "INSERT INTO `destination_entities` (`double_value`) SELECT ASIN(NEW.`double_value`);";
protected override string ExceptedAsinSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT ASIN(NEW.`DoubleValue`);";

protected override string ExceptedAtanSql => "INSERT INTO `destination_entities` (`double_value`) SELECT ATAN(NEW.`double_value`);";
protected override string ExceptedAtanSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT ATAN(NEW.`DoubleValue`);";

protected override string ExceptedAtan2Sql => "INSERT INTO `destination_entities` (`double_value`) SELECT ATAN2(NEW.`double_value`, NEW.`double_value`);";
protected override string ExceptedAtan2Sql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT ATAN2(NEW.`DoubleValue`, NEW.`DoubleValue`);";

protected override string ExceptedCeilingSql => "INSERT INTO `destination_entities` (`double_value`) SELECT CEILING(NEW.`double_value`);";
protected override string ExceptedCeilingSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT CEILING(NEW.`DoubleValue`);";

protected override string ExceptedCosSql => "INSERT INTO `destination_entities` (`double_value`) SELECT COS(NEW.`double_value`);";
protected override string ExceptedCosSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT COS(NEW.`DoubleValue`);";

protected override string ExceptedExpSql => "INSERT INTO `destination_entities` (`double_value`) SELECT EXP(NEW.`double_value`);";
protected override string ExceptedExpSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT EXP(NEW.`DoubleValue`);";

protected override string ExceptedFloorSql => "INSERT INTO `destination_entities` (`double_value`) SELECT FLOOR(NEW.`double_value`);";
protected override string ExceptedFloorSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT FLOOR(NEW.`DoubleValue`);";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ public MySqlUnitMemberAssignmentFunctionsTests() : base(
{
}

public override string ExceptedEnumValueSql => "INSERT INTO `destination_entities` (`enum_value`) SELECT NEW.`enum_value`;";
public override string ExceptedEnumValueSql => "INSERT INTO `DestinationEntities` (`EnumValue`) SELECT NEW.`EnumValue`;";

public override string ExceptedDecimalAddSql => "INSERT INTO `destination_entities` (`decimal_value`) SELECT NEW.`decimal_value` + 3;";
public override string ExceptedDecimalAddSql => "INSERT INTO `DestinationEntities` (`DecimalValue`) SELECT NEW.`DecimalValue` + 3;";

public override string ExceptedDoubleSubSql => "INSERT INTO `destination_entities` (`double_value`) SELECT NEW.`double_value` + 3;";
public override string ExceptedDoubleSubSql => "INSERT INTO `DestinationEntities` (`DoubleValue`) SELECT NEW.`DoubleValue` + 3;";

public override string ExceptedIntMultiplySql => "INSERT INTO `destination_entities` (`int_value`) SELECT NEW.`int_value` * 2;";
public override string ExceptedIntMultiplySql => "INSERT INTO `DestinationEntities` (`IntValue`) SELECT NEW.`IntValue` * 2;";

public override string ExceptedBooleanSql => "INSERT INTO `destination_entities` (`boolean_value`) SELECT NEW.`boolean_value` IS FALSE;";
public override string ExceptedBooleanSql => "INSERT INTO `DestinationEntities` (`BooleanValue`) SELECT NEW.`BooleanValue` IS FALSE;";

public override string ExceptedNewGuidSql => "INSERT INTO `destination_entities` (`guid_value`) SELECT UUID();";
public override string ExceptedNewGuidSql => "INSERT INTO `DestinationEntities` (`GuidValue`) SELECT UUID();";

public override string ExceptedCharVariableSql => "INSERT INTO `destination_entities` (`char_value`) SELECT NEW.`char_value`;";
public override string ExceptedCharVariableSql => "INSERT INTO `DestinationEntities` (`CharValue`) SELECT NEW.`CharValue`;";

public override string ExceptedCharValueSql => "INSERT INTO `destination_entities` (`char_value`) SELECT 'a';";
public override string ExceptedCharValueSql => "INSERT INTO `DestinationEntities` (`CharValue`) SELECT 'a';";

public override string ExceptedDateTimeOffsetNowSql => "INSERT INTO `destination_entities` (`date_time_offset_value`) SELECT LOCALTIME();";
public override string ExceptedDateTimeOffsetUtcNowSql => "INSERT INTO `destination_entities` (`date_time_offset_value`) SELECT UTC_TIMESTAMP();";
public override string ExceptedDateTimeOffsetNowSql => "INSERT INTO `DestinationEntities` (`DateTimeOffsetValue`) SELECT LOCALTIME();";
public override string ExceptedDateTimeOffsetUtcNowSql => "INSERT INTO `DestinationEntities` (`DateTimeOffsetValue`) SELECT UTC_TIMESTAMP();";

public override string ExceptedNewDateTimeOffsetSql => "INSERT INTO `destination_entities` (`date_time_offset_value`) SELECT '1000-01-01';";
public override string ExceptedNewDateTimeSql => "INSERT INTO `destination_entities` (`date_time_value`) SELECT '1000-01-01';";
public override string ExceptedNewDateTimeOffsetSql => "INSERT INTO `DestinationEntities` (`DateTimeOffsetValue`) SELECT '1000-01-01';";
public override string ExceptedNewDateTimeSql => "INSERT INTO `DestinationEntities` (`DateTimeValue`) SELECT '1000-01-01';";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public MySqlUnitRawSqlTests() : base(
{
}

protected override string ExceptedInsertTriggerSqlForMemberArgs => "PERFORM func(NEW.`boolean_value`, NEW.`double_value`, `source_entities`)";
protected override string ExceptedInsertTriggerSqlForComputedArgs => "PERFORM func(NEW.`double_value` + 10)";
protected override string ExceptedInsertTriggerSqlForMemberArgs => "PERFORM func(NEW.`BooleanValue`, NEW.`DoubleValue`, `SourceEntities`)";
protected override string ExceptedInsertTriggerSqlForComputedArgs => "PERFORM func(NEW.`DoubleValue` + 10)";
protected override string ExceptedInsertTriggerSqlWhenNoArgs => "PERFORM func()";
protected override string ExceptedUpdateTriggerSqlForMemberArgs => "PERFORM func(OLD.`decimal_value`, NEW.`decimal_value`)";
protected override string ExceptedDeleteTriggerSqlForMemberArgs => "PERFORM func(OLD.`decimal_value`, OLD.`double_value`)";
protected override string ExceptedUpdateTriggerSqlForMemberArgs => "PERFORM func(OLD.`DecimalValue`, NEW.`DecimalValue`)";
protected override string ExceptedDeleteTriggerSqlForMemberArgs => "PERFORM func(OLD.`DecimalValue`, OLD.`DoubleValue`)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ public MySqlUnitStringFunctionsTests() : base(
{
}

protected override string ExceptedConcatSql => "INSERT INTO `destination_entities` (`string_field`) SELECT CONCAT(NEW.`string_field`, 'abc');";
protected override string ExceptedConcatSql => "INSERT INTO `DestinationEntities` (`StringField`) SELECT CONCAT(NEW.`StringField`, 'abc');";

protected override string ExceptedStringLowerSql => "INSERT INTO `destination_entities` (`string_field`) SELECT LOWER(NEW.`string_field`);";
protected override string ExceptedStringLowerSql => "INSERT INTO `DestinationEntities` (`StringField`) SELECT LOWER(NEW.`StringField`);";

protected override string ExceptedStringUpperSql => "INSERT INTO `destination_entities` (`string_field`) SELECT UPPER(NEW.`string_field`);";
protected override string ExceptedStringUpperSql => "INSERT INTO `DestinationEntities` (`StringField`) SELECT UPPER(NEW.`StringField`);";

protected override string ExceptedStringTrimSql => "INSERT INTO `destination_entities` (`string_field`) SELECT TRIM(NEW.`string_field`);";
protected override string ExceptedStringTrimSql => "INSERT INTO `DestinationEntities` (`StringField`) SELECT TRIM(NEW.`StringField`);";

protected override string ExceptedContainsSql => "INSERT INTO `destination_entities` (`boolean_value`) SELECT INSTR(NEW.`string_field`, 'abc') > 0;";
protected override string ExceptedContainsSql => "INSERT INTO `DestinationEntities` (`BooleanValue`) SELECT INSTR(NEW.`StringField`, 'abc') > 0;";

protected override string ExceptedEndsWithSql => "INSERT INTO `destination_entities` (`boolean_value`) SELECT NEW.`string_field` LIKE CONCAT('%', 'abc');";
protected override string ExceptedEndsWithSql => "INSERT INTO `DestinationEntities` (`BooleanValue`) SELECT NEW.`StringField` LIKE CONCAT('%', 'abc');";

protected override string ExceptedIsNullOrEmptySql => "INSERT INTO `destination_entities` (`boolean_value`) SELECT NEW.`string_field` IS NULL OR NEW.`string_field` = '';";
protected override string ExceptedIsNullOrEmptySql => "INSERT INTO `DestinationEntities` (`BooleanValue`) SELECT NEW.`StringField` IS NULL OR NEW.`StringField` = '';";

protected override string ExceptedCoalesceStringSql => "INSERT INTO `destination_entities` (`string_field`) SELECT COALESCE(NEW.`string_field`, 'John');";
protected override string ExceptedCoalesceStringSql => "INSERT INTO `DestinationEntities` (`StringField`) SELECT COALESCE(NEW.`StringField`, 'John');";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public DbContextOptions<TContext> CreateDbContextOptions()
return new DbContextOptionsBuilder<TContext>()
.UseNpgsql("User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=efcoretriggers;",
x => x.MigrationsAssembly(typeof(TContext).Assembly.FullName))
.UseSnakeCaseNamingConvention()
.UsePostgreSqlTriggers()
.ReplaceService<IModelCacheKeyFactory, DynamicModelCacheKeyFactoryDesignTimeSupport>()
.Options;
Expand Down
Loading

0 comments on commit 019f2ca

Please sign in to comment.