-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathExtensions.cs
More file actions
23 lines (18 loc) · 764 Bytes
/
Extensions.cs
File metadata and controls
23 lines (18 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace PhenX.EntityFrameworkCore.BulkInsert.Tests.DbContext;
public static class Extensions
{
public static PropertyBuilder<T> AsJsonString<T>(this PropertyBuilder<T> propertyBuilder, string? columnType)
where T : class?
{
var converter = new ValueConverter<T, string>(
v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),
v => JsonSerializer.Deserialize<T>(v, (JsonSerializerOptions?)null)!
);
propertyBuilder.HasConversion(converter).HasColumnType(columnType);
return propertyBuilder;
}
}