Skip to content

Commit 387eb2a

Browse files
committed
.Net 10
1 parent 6a959eb commit 387eb2a

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests/ConnectionExtensions/BaseTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests.Database;
22
using EntityFrameworkCore.SqlServer.SimpleBulks.Extensions;
33
using Microsoft.Data.SqlClient;
4+
using System.Text.Json;
45
using Xunit.Abstractions;
56

67
namespace EntityFrameworkCore.SqlServer.SimpleBulks.ConnectionExtensionsTests.ConnectionExtensions;
@@ -35,7 +36,9 @@ protected BaseTest(ITestOutputHelper output, SqlServerFixture fixture, string db
3536
.ConfigureComplexProperty(x => x.ComplexShippingAddress.Location)
3637
.ConfigureComplexProperty(x => x.OwnedShippingAddress)
3738
.ConfigureComplexProperty(x => x.OwnedShippingAddress.Location)
38-
.ConfigurePropertyConversion(x => x.SeasonAsString, y => y.ToString(), z => (Season)Enum.Parse(typeof(Season), z));
39+
.ConfigurePropertyConversion(x => x.SeasonAsString, y => y.ToString(), z => (Season)Enum.Parse(typeof(Season), z))
40+
.ConfigureJsonProperty(x => x.JsonComplexShippingAddress, y => JsonSerializer.Serialize(y))
41+
.ConfigureJsonProperty(x => x.JsonOwnedShippingAddress, y => JsonSerializer.Serialize(y));
3942

4043
if (_enableDiscriminator)
4144
{

src/EntityFrameworkCore.SqlServer.SimpleBulks/SqlTableInforBuilder.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,36 @@ public SqlTableInforBuilder<T> ConfigureDiscriminator<TProperty>(Expression<Func
206206
return ConfigureDiscriminator(propertyName, value, columnName, columnType);
207207
}
208208

209+
public SqlTableInforBuilder<T> ConfigureJsonProperty<TProperty>(string propertyName, Func<TProperty, string?> convertToJson)
210+
{
211+
_valueConverters[propertyName] = new ValueConverter
212+
{
213+
PropertyName = propertyName,
214+
ProviderClrType = typeof(string),
215+
ConvertToProvider = obj => convertToJson((TProperty?)obj)
216+
};
217+
218+
if (!_propertyNames.Contains(propertyName))
219+
{
220+
_propertyNames.Add(propertyName);
221+
}
222+
223+
if (!_insertablePropertyNames.Contains(propertyName))
224+
{
225+
_insertablePropertyNames.Add(propertyName);
226+
}
227+
228+
return this;
229+
}
230+
231+
public SqlTableInforBuilder<T> ConfigureJsonProperty<TProperty>(Expression<Func<T, TProperty>> nameSelector, Func<TProperty, string?> convertToJson)
232+
{
233+
var propertyName = nameSelector.Body.GetMemberName();
234+
235+
return ConfigureJsonProperty(propertyName, convertToJson);
236+
}
237+
238+
209239
public SqlTableInfor<T> Build()
210240
{
211241
if (_outputId?.Mode == OutputIdMode.ServerGenerated && _insertablePropertyNames.Contains(_outputId.Name))

0 commit comments

Comments
 (0)