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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class ColumnMetadata(IProperty property, SqlDialectBuilder dial

public bool IsGenerated { get; } = property.ValueGenerated != ValueGenerated.Never;

public object? GetValue(object entity, BulkInsertOptions options)
public object GetValue(object entity, BulkInsertOptions options)
{
var result = _getter(entity);

Expand All @@ -40,7 +40,7 @@ internal sealed class ColumnMetadata(IProperty property, SqlDialectBuilder dial
}
}

return result;
return result ?? DBNull.Value;
}

private static Func<object, object?> BuildGetter(IProperty property)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;

public class JsonDbObject
{
public int Code { get; set; }

public string Name { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TestEntityWithJson>(b =>
{
b.Property(x => x.Json).AsJsonString("jsonb");
b.Property(x => x.JsonArray).AsJsonString("jsonb");
b.Property(x => x.JsonObject).AsJsonString("jsonb");
});

modelBuilder.Entity<TestEntity>(b =>
Expand All @@ -54,7 +55,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TestEntityWithJson>(b =>
{
b.Property(x => x.Json).AsJsonString("json");
b.Property(x => x.JsonArray).AsJsonString("json");
b.Property(x => x.JsonObject).AsJsonString("json");
});

modelBuilder.Entity<TestEntity>(b =>
Expand All @@ -72,7 +74,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TestEntityWithJson>(b =>
{
b.Property(x => x.Json).AsJsonString(null);
b.Property(x => x.JsonArray).AsJsonString(null);
b.Property(x => x.JsonObject).AsJsonString(null);
});

modelBuilder.Entity<TestEntity>(b =>
Expand All @@ -90,7 +93,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TestEntityWithJson>(b =>
{
b.Property(x => x.Json).AsJsonString(null);
b.Property(x => x.JsonArray).AsJsonString(null);
b.Property(x => x.JsonObject).AsJsonString(null);
});

modelBuilder.Entity<TestEntity>(b =>
Expand All @@ -108,7 +112,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<TestEntityWithJson>(b =>
{
b.Property(x => x.Json).AsJsonString(null);
b.Property(x => x.JsonArray).AsJsonString(null);
b.Property(x => x.JsonObject).AsJsonString(null);
});

modelBuilder.Entity<TestEntity>(b =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public class TestEntity : TestEntityBase
[Column("the_identifier")]
public Guid Identifier { get; set; }

[Column("nullable_identifier")]
public Guid? NullableIdentifier { get; set; }

public DateTime Created { get; set; }

public DateTime? Modified { get; set; }

[Column("string_enum_value")]
public StringEnum StringEnumValue { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
[Key]
public int Id { get; set; }

public List<int> Json { get; set; } = [];
public List<int> JsonArray { get; set; } = [];

public JsonDbObject JsonObject { get; set; }

Check warning on line 14 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestEntityWithJson.cs

View workflow job for this annotation

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

Non-nullable property 'JsonObject' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestEntityWithJson.cs

View workflow job for this annotation

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

Non-nullable property 'JsonObject' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestEntityWithJson.cs

View workflow job for this annotation

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

Non-nullable property 'JsonObject' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 14 in tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestEntityWithJson.cs

View workflow job for this annotation

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

Non-nullable property 'JsonObject' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ public async Task InsertEntities_WithJson(InsertStrategy strategy)
// Arrange
var entities = new List<TestEntityWithJson>
{
new TestEntityWithJson { Json = [1] },
new TestEntityWithJson { Json = [2] }
new TestEntityWithJson
{
JsonArray = [1],
JsonObject = new JsonDbObject { Code = 1, Name = "Test1" },
},
new TestEntityWithJson
{
JsonArray = [2],
JsonObject = new JsonDbObject { Code = 2, Name = "Test2" },
},
};

// Act
Expand Down