Skip to content

Commit 9c114fb

Browse files
author
fabien.menager
committed
Fix nullable values handlings and add tests
1 parent 17cca52 commit 9c114fb

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/PhenX.EntityFrameworkCore.BulkInsert/Metadata/ColumnMetadata.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal sealed class ColumnMetadata(IProperty property, SqlDialectBuilder dial
2424

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

27-
public object? GetValue(object entity, BulkInsertOptions options)
27+
public object GetValue(object entity, BulkInsertOptions options)
2828
{
2929
var result = _getter(entity);
3030

@@ -40,7 +40,7 @@ internal sealed class ColumnMetadata(IProperty property, SqlDialectBuilder dial
4040
}
4141
}
4242

43-
return result;
43+
return result ?? DBNull.Value;
4444
}
4545

4646
private static Func<object, object?> BuildGetter(IProperty property)

tests/PhenX.EntityFrameworkCore.BulkInsert.Tests/DbContext/TestEntity.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ public class TestEntity : TestEntityBase
2222
[Column("the_identifier")]
2323
public Guid Identifier { get; set; }
2424

25+
[Column("nullable_identifier")]
26+
public Guid? NullableIdentifier { get; set; }
27+
28+
public DateTime Created { get; set; }
29+
30+
public DateTime? Modified { get; set; }
31+
2532
[Column("string_enum_value")]
2633
public StringEnum StringEnumValue { get; set; }
2734

0 commit comments

Comments
 (0)