Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2025.2.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="NetTopologySuite" Version="2.6.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.0.*" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Oracle.EntityFrameworkCore" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.23.80" />
<PackageReference Include="Oracle.EntityFrameworkCore" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.23.80" />
<PackageReference Include="Oracle.EntityFrameworkCore" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.23.90" />
<PackageReference Include="Oracle.EntityFrameworkCore" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.23.90" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ internal static class PropertyAccessor
// instance => converter(body)
var invokeConverter = Expression.Invoke(converter, converterInput);

if (body.Type.IsClass)
// If the property is a reference type, we need to check for null before calling the converter
if (body.Type.IsClass && !invokeConverter.Type.IsValueType)
{
// instance => body == null ? null : converter(body)
var nullCondition = Expression.Equal(body, Expression.Constant(null, body.Type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.4" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.4.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.4.0" />
<PackageReference Include="Testcontainers.MySql" Version="4.4.0" />
Expand All @@ -16,13 +16,13 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="EFCore.BulkExtensions" Version="8.1.3" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="8.103.8.1" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="8.104.0.1" />
<PackageReference Include="linq2db.EntityFrameworkCore" Version="8.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="EFCore.BulkExtensions" Version="9.0.1" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="9.103.8.1" />
<PackageReference Include="EFCore.BulkExtensions" Version="9.0.2" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="9.104.0.1" />
<PackageReference Include="linq2db.EntityFrameworkCore" Version="9.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

using SmartEnum.EFCore;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

public class TestDbContext : TestDbContextBase
Expand All @@ -11,13 +13,16 @@ public class TestDbContext : TestDbContextBase
public DbSet<TestEntityWithGuidId> TestEntitiesWithGuidId { get; set; } = null!;
public DbSet<TestEntityWithConverters> TestEntitiesWithConverter { get; set; } = null!;
public DbSet<TestEntityWithComplexType> TestEntitiesWithComplexType { get; set; } = null!;
public DbSet<TestEntityWithSmartEnum> TestEntitiesWithSmartEnum { get; set; } = null!;
public DbSet<Student> Students { get; set; } = null!;
public DbSet<Course> Courses { get; set; } = null!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.ConfigureSmartEnum();

modelBuilder.Entity<TestEntityWithConverters>(builder =>
{
builder.Property(e => e.CreatedAt)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

[PrimaryKey(nameof(Id))]
public class TestEntityWithSmartEnum : TestEntityBase
{
public int Id { get; set; }

public TestSmartEnum Enum { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Ardalis.SmartEnum;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

public class TestSmartEnum : SmartEnum<TestSmartEnum>
{
private TestSmartEnum(string name, int value) : base(name, value)
{
}

public static readonly TestSmartEnum Value = new TestSmartEnum("test", 1);

Check warning on line 11 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestSmartEnum.cs

View workflow job for this annotation

GitHub Actions / build (net8.0, 8.0.x)

'TestSmartEnum.Value' hides inherited member 'SmartEnum<TestSmartEnum, int>.Value'. Use the new keyword if hiding was intended.

Check warning on line 11 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestSmartEnum.cs

View workflow job for this annotation

GitHub Actions / build (net8.0, 8.0.x)

'TestSmartEnum.Value' hides inherited member 'SmartEnum<TestSmartEnum, int>.Value'. Use the new keyword if hiding was intended.

Check warning on line 11 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestSmartEnum.cs

View workflow job for this annotation

GitHub Actions / build (net9.0, 9.0.x)

'TestSmartEnum.Value' hides inherited member 'SmartEnum<TestSmartEnum, int>.Value'. Use the new keyword if hiding was intended.

Check warning on line 11 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestSmartEnum.cs

View workflow job for this annotation

GitHub Actions / build (net9.0, 9.0.x)

'TestSmartEnum.Value' hides inherited member 'SmartEnum<TestSmartEnum, int>.Value'. Use the new keyword if hiding was intended.
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,38 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="Xunit.Combinatorial" Version="1.6.24" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" Version="1.5.23" />
</ItemGroup>

<ItemGroup Label="Test containers">
<PackageReference Include="Testcontainers" Version="4.4.0" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.4.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.4.0" />
<PackageReference Include="Testcontainers.MySql" Version="4.4.0" />
<PackageReference Include="Testcontainers.Oracle" Version="4.4.0" />
<PackageReference Include="Testcontainers" Version="4.7.0" />
<PackageReference Include="Testcontainers.PostgreSql" Version="4.7.0" />
<PackageReference Include="Testcontainers.MsSql" Version="4.7.0" />
<PackageReference Include="Testcontainers.MySql" Version="4.7.0" />
<PackageReference Include="Testcontainers.Oracle" Version="4.7.0" />
</ItemGroup>

<ItemGroup Label="NetTopologySuite net8.0" Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="8.0.16" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="8.0.20" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="8.0.11" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="8.0.3" />
</ItemGroup>

<ItemGroup Label="NetTopologySuite net9.0" Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite" Version="9.0.9" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="9.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="9.0.0" />
</ItemGroup>

<ItemGroup Label="Specific dependencies">
<PackageReference Include="Ardalis.SmartEnum.EFCore" Version="8.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using FluentAssertions;

using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

using Xunit;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Various;

public abstract class VariousTestsBase<TDbContext>(TestDbContainer dbContainer) : IAsyncLifetime
where TDbContext : TestDbContext, new()
{
private readonly Guid _run = Guid.NewGuid();
private TDbContext _context = null!;

public async Task InitializeAsync()
{
_context = await dbContainer.CreateContextAsync<TDbContext>("various");
}

public Task DisposeAsync()
{
_context.Dispose();
return Task.CompletedTask;
}

[SkippableTheory]
[CombinatorialData]
public async Task InsertSmartEnumEntities(InsertStrategy strategy)
{
// Arrange
var entities = new List<TestEntityWithSmartEnum>
{
new TestEntityWithSmartEnum { TestRun = _run, Enum = TestSmartEnum.Value},
new TestEntityWithSmartEnum { TestRun = _run, Enum = TestSmartEnum.Value}
};

// Act
var insertedEntities = await _context.InsertWithStrategyAsync(strategy, entities);

// Assert
insertedEntities.Should().BeEquivalentTo(entities,
o => o.RespectingRuntimeTypes().Excluding(e => e.Id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

using Xunit;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Various;

[Trait("Category", "MySql")]
[Collection(TestDbContainerMySqlCollection.Name)]
public class VariousTestsMySql(TestDbContainerMySql dbContainer) : VariousTestsBase<TestDbContextMySql>(dbContainer)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

using Xunit;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Various;

[Trait("Category", "Oracle")]
[Collection(TestDbContainerOracleCollection.Name)]
public class VariousTestsOracle(TestDbContainerOracle dbContainer) : VariousTestsBase<TestDbContextOracle>(dbContainer)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

using Xunit;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Various;

[Trait("Category", "PostgreSql")]
[Collection(TestDbContainerPostgreSqlCollection.Name)]
public class VariousTestsPostgreSql(TestDbContainerPostgreSql dbContainer) : VariousTestsBase<TestDbContextPostgreSql>(dbContainer)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

using Xunit;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Various;

[Trait("Category", "SqlServer")]
[Collection(TestDbContainerSqlServerCollection.Name)]
public class VariousTestsSqlServer(TestDbContainerSqlServer dbContainer) : VariousTestsBase<TestDbContextSqlServer>(dbContainer)
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContainer;
using PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

using Xunit;

namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.Tests.Various;

[Trait("Category", "Sqlite")]
[Collection(TestDbContainerSqliteCollection.Name)]
public class VariousTestsSqlite(TestDbContainerSqlite dbContainer) : VariousTestsBase<TestDbContextSqlite>(dbContainer)
{
}