Skip to content

Commit 9d83dbf

Browse files
committed
.Net 10
1 parent cefd49c commit 9d83dbf

4 files changed

Lines changed: 115 additions & 111 deletions

File tree

src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/GetPropertiesTests.cs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -284,25 +284,25 @@ public void GetProperties_JsonComplexType_ReturnsCorrectColumnInformation()
284284
Assert.False(property.IsPrimaryKey);
285285
Assert.False(property.IsRowVersion);
286286
Assert.True(property.IsJson);
287-
Assert.NotNull(property.JsonPropertyWriters);
287+
Assert.NotNull(property.JsonProperties);
288288

289-
// Verify that the JsonPropertyWriters have correct structure
290-
var writers = property.JsonPropertyWriters;
291-
var flattenedWriters = property.GetFlattenedJsonPropertyWriters();
292-
Assert.Equal(2, writers.Count); // Street and Location
289+
// Verify that the JsonProperties have correct structure
290+
var jsonProperties = property.JsonProperties;
291+
var flattenedJsonProperties = property.FlattenedJsonProperties;
292+
Assert.Equal(2, jsonProperties.Count); // Street and Location
293293

294-
var streetWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Street");
294+
var streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street");
295295
Assert.NotNull(streetWriter);
296296
Assert.Equal("Street", streetWriter.JsonPropertyName);
297-
Assert.Equal("Street", streetWriter.FullJsonPath);
297+
Assert.Equal("Street", streetWriter.FullJsonPropertyName);
298298
Assert.Equal("Street", streetWriter.FullClrPropertyName);
299299
Assert.Equal(typeof(string), streetWriter.PropertyType);
300300
Assert.False(streetWriter.IsNestedComplexType);
301301

302-
var locationWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Location");
302+
var locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location");
303303
Assert.NotNull(locationWriter);
304304
Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext
305-
Assert.Equal("xxx", locationWriter.FullJsonPath);
305+
Assert.Equal("xxx", locationWriter.FullJsonPropertyName);
306306
Assert.Equal("Location", locationWriter.FullClrPropertyName);
307307
Assert.Equal(typeof(ComplexTypeLocation), locationWriter.PropertyType);
308308
Assert.True(locationWriter.IsNestedComplexType);
@@ -311,17 +311,17 @@ public void GetProperties_JsonComplexType_ReturnsCorrectColumnInformation()
311311

312312
var latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat");
313313
Assert.NotNull(latWriter);
314-
Assert.Equal("xxx.Lat", latWriter.FullJsonPath);
314+
Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName);
315315
Assert.Equal("Location.Lat", latWriter.FullClrPropertyName);
316316
Assert.Equal(typeof(double), latWriter.PropertyType);
317317

318318
var lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng");
319319
Assert.NotNull(lngWriter);
320-
Assert.Equal("xxx.Lng", lngWriter.FullJsonPath);
320+
Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName);
321321
Assert.Equal("Location.Lng", lngWriter.FullClrPropertyName);
322322
Assert.Equal(typeof(double), lngWriter.PropertyType);
323323

324-
// Verify serialization using JsonPropertyWriters
324+
// Verify serialization using JsonProperties
325325
var testAddress = new ComplexTypeAddress
326326
{
327327
Street = "123 Main St",
@@ -332,7 +332,7 @@ public void GetProperties_JsonComplexType_ReturnsCorrectColumnInformation()
332332
}
333333
};
334334

335-
var json = JsonPropertyWriter.Serialize(testAddress, writers);
335+
var json = JsonProperty.Serialize(testAddress, jsonProperties);
336336
Assert.NotNull(json);
337337
Assert.Contains("Street", json);
338338
Assert.Contains("123 Main St", json);
@@ -373,25 +373,25 @@ public void GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation()
373373
Assert.False(property.IsPrimaryKey);
374374
Assert.False(property.IsRowVersion);
375375
Assert.True(property.IsJson);
376-
Assert.NotNull(property.JsonPropertyWriters);
376+
Assert.NotNull(property.JsonProperties);
377377

378-
// Verify that the JsonPropertyWriters have correct structure
379-
var writers = property.JsonPropertyWriters;
380-
var flattenedWriters = property.GetFlattenedJsonPropertyWriters();
381-
Assert.Equal(3, writers.Count); // Street and Location
378+
// Verify that the JsonProperties have correct structure
379+
var jsonProperties = property.JsonProperties;
380+
var flattenedJsonProperties = property.FlattenedJsonProperties;
381+
Assert.Equal(3, jsonProperties.Count); // Street and Location
382382

383-
var streetWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Street");
383+
var streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street");
384384
Assert.NotNull(streetWriter);
385385
Assert.Equal("Street", streetWriter.JsonPropertyName);
386-
Assert.Equal("Street", streetWriter.FullJsonPath);
386+
Assert.Equal("Street", streetWriter.FullJsonPropertyName);
387387
Assert.Equal("Street", streetWriter.FullClrPropertyName);
388388
Assert.Equal(typeof(string), streetWriter.PropertyType);
389389
Assert.False(streetWriter.IsNestedComplexType);
390390

391-
var locationWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Location");
391+
var locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location");
392392
Assert.NotNull(locationWriter);
393393
Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext
394-
Assert.Equal("xxx", locationWriter.FullJsonPath);
394+
Assert.Equal("xxx", locationWriter.FullJsonPropertyName);
395395
Assert.Equal("Location", locationWriter.FullClrPropertyName);
396396
Assert.Equal(typeof(OwnedTypeLocation), locationWriter.PropertyType);
397397
Assert.True(locationWriter.IsNestedComplexType);
@@ -400,17 +400,17 @@ public void GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation()
400400

401401
var latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat");
402402
Assert.NotNull(latWriter);
403-
Assert.Equal("xxx.Lat", latWriter.FullJsonPath);
403+
Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName);
404404
Assert.Equal("Location.Lat", latWriter.FullClrPropertyName);
405405
Assert.Equal(typeof(double), latWriter.PropertyType);
406406

407407
var lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng");
408408
Assert.NotNull(lngWriter);
409-
Assert.Equal("xxx.Lng", lngWriter.FullJsonPath);
409+
Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName);
410410
Assert.Equal("Location.Lng", lngWriter.FullClrPropertyName);
411411
Assert.Equal(typeof(double), lngWriter.PropertyType);
412412

413-
// Verify serialization using JsonPropertyWriters
413+
// Verify serialization using JsonProperties
414414
var testAddress = new OwnedTypeAddress
415415
{
416416
Street = "123 Main St",
@@ -421,7 +421,7 @@ public void GetProperties_JsonOwnedType_ReturnsCorrectColumnInformation()
421421
}
422422
};
423423

424-
var json = JsonPropertyWriter.Serialize(testAddress, writers);
424+
var json = JsonProperty.Serialize(testAddress, jsonProperties);
425425
Assert.NotNull(json);
426426
Assert.Contains("Street", json);
427427
Assert.Contains("123 Main St", json);
@@ -460,25 +460,25 @@ public void GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation()
460460
Assert.False(property.IsPrimaryKey);
461461
Assert.False(property.IsRowVersion);
462462
Assert.True(property.IsJson);
463-
Assert.NotNull(property.JsonPropertyWriters);
463+
Assert.NotNull(property.JsonProperties);
464464

465-
// Verify that the JsonPropertyWriters have correct structure
466-
var writers = property.JsonPropertyWriters;
467-
var flattenedWriters = property.GetFlattenedJsonPropertyWriters();
468-
Assert.Equal(2, writers.Count); // Street and Location
465+
// Verify that the JsonProperties have correct structure
466+
var jsonProperties = property.JsonProperties;
467+
var flattenedJsonProperties = property.FlattenedJsonProperties;
468+
Assert.Equal(2, jsonProperties.Count); // Street and Location
469469

470-
var streetWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Street");
470+
var streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street");
471471
Assert.NotNull(streetWriter);
472472
Assert.Equal("Street", streetWriter.JsonPropertyName);
473-
Assert.Equal("Street", streetWriter.FullJsonPath);
473+
Assert.Equal("Street", streetWriter.FullJsonPropertyName);
474474
Assert.Equal("Street", streetWriter.FullClrPropertyName);
475475
Assert.Equal(typeof(string), streetWriter.PropertyType);
476476
Assert.False(streetWriter.IsNestedComplexType);
477477

478-
var locationWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Location");
478+
var locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location");
479479
Assert.NotNull(locationWriter);
480480
Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext
481-
Assert.Equal("xxx", locationWriter.FullJsonPath);
481+
Assert.Equal("xxx", locationWriter.FullJsonPropertyName);
482482
Assert.Equal("Location", locationWriter.FullClrPropertyName);
483483
Assert.Equal(typeof(ComplexTypeLocation), locationWriter.PropertyType);
484484
Assert.True(locationWriter.IsNestedComplexType);
@@ -487,17 +487,17 @@ public void GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation()
487487

488488
var latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat");
489489
Assert.NotNull(latWriter);
490-
Assert.Equal("xxx.Lat", latWriter.FullJsonPath);
490+
Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName);
491491
Assert.Equal("Location.Lat", latWriter.FullClrPropertyName);
492492
Assert.Equal(typeof(double), latWriter.PropertyType);
493493

494494
var lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng");
495495
Assert.NotNull(lngWriter);
496-
Assert.Equal("xxx.Lng", lngWriter.FullJsonPath);
496+
Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName);
497497
Assert.Equal("Location.Lng", lngWriter.FullClrPropertyName);
498498
Assert.Equal(typeof(double), lngWriter.PropertyType);
499499

500-
// Verify serialization using JsonPropertyWriters
500+
// Verify serialization using JsonProperties
501501
var testComplexAddress = new ComplexTypeAddress
502502
{
503503
Street = "123 Main St",
@@ -508,7 +508,7 @@ public void GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation()
508508
}
509509
};
510510

511-
var json = JsonPropertyWriter.Serialize(testComplexAddress, writers);
511+
var json = JsonProperty.Serialize(testComplexAddress, jsonProperties);
512512
Assert.NotNull(json);
513513
Assert.Contains("Street", json);
514514
Assert.Contains("123 Main St", json);
@@ -525,25 +525,25 @@ public void GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation()
525525
Assert.False(property.IsPrimaryKey);
526526
Assert.False(property.IsRowVersion);
527527
Assert.True(property.IsJson);
528-
Assert.NotNull(property.JsonPropertyWriters);
528+
Assert.NotNull(property.JsonProperties);
529529

530-
// Verify that the JsonPropertyWriters have correct structure
531-
writers = property.JsonPropertyWriters;
532-
flattenedWriters = property.GetFlattenedJsonPropertyWriters();
533-
Assert.Equal(3, writers.Count); // Street and Location
530+
// Verify that the JsonProperties have correct structure
531+
jsonProperties = property.JsonProperties;
532+
flattenedJsonProperties = property.FlattenedJsonProperties;
533+
Assert.Equal(3, jsonProperties.Count); // Street and Location
534534

535-
streetWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Street");
535+
streetWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Street");
536536
Assert.NotNull(streetWriter);
537537
Assert.Equal("Street", streetWriter.JsonPropertyName);
538-
Assert.Equal("Street", streetWriter.FullJsonPath);
538+
Assert.Equal("Street", streetWriter.FullJsonPropertyName);
539539
Assert.Equal("Street", streetWriter.FullClrPropertyName);
540540
Assert.Equal(typeof(string), streetWriter.PropertyType);
541541
Assert.False(streetWriter.IsNestedComplexType);
542542

543-
locationWriter = writers.FirstOrDefault(w => w.ClrPropertyName == "Location");
543+
locationWriter = jsonProperties.FirstOrDefault(w => w.ClrPropertyName == "Location");
544544
Assert.NotNull(locationWriter);
545545
Assert.Equal("xxx", locationWriter.JsonPropertyName); // Mapped to "xxx" in TestDbContext
546-
Assert.Equal("xxx", locationWriter.FullJsonPath);
546+
Assert.Equal("xxx", locationWriter.FullJsonPropertyName);
547547
Assert.Equal("Location", locationWriter.FullClrPropertyName);
548548
Assert.Equal(typeof(OwnedTypeLocation), locationWriter.PropertyType);
549549
Assert.True(locationWriter.IsNestedComplexType);
@@ -552,17 +552,17 @@ public void GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation()
552552

553553
latWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lat");
554554
Assert.NotNull(latWriter);
555-
Assert.Equal("xxx.Lat", latWriter.FullJsonPath);
555+
Assert.Equal("xxx.Lat", latWriter.FullJsonPropertyName);
556556
Assert.Equal("Location.Lat", latWriter.FullClrPropertyName);
557557
Assert.Equal(typeof(double), latWriter.PropertyType);
558558

559559
lngWriter = locationWriter.NestedProperties.FirstOrDefault(w => w.ClrPropertyName == "Lng");
560560
Assert.NotNull(lngWriter);
561-
Assert.Equal("xxx.Lng", lngWriter.FullJsonPath);
561+
Assert.Equal("xxx.Lng", lngWriter.FullJsonPropertyName);
562562
Assert.Equal("Location.Lng", lngWriter.FullClrPropertyName);
563563
Assert.Equal(typeof(double), lngWriter.PropertyType);
564564

565-
// Verify serialization using JsonPropertyWriters
565+
// Verify serialization using JsonProperties
566566
var testOwnedAddress = new OwnedTypeAddress
567567
{
568568
Street = "123 Main St",
@@ -573,7 +573,7 @@ public void GetProperties_JsonComplexOwnedType_ReturnsCorrectColumnInformation()
573573
}
574574
};
575575

576-
json = JsonPropertyWriter.Serialize(testOwnedAddress, writers);
576+
json = JsonProperty.Serialize(testOwnedAddress, jsonProperties);
577577
Assert.NotNull(json);
578578
Assert.Contains("Street", json);
579579
Assert.Contains("123 Main St", json);

src/EntityFrameworkCore.SqlServer.SimpleBulks/ColumnInfor.cs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,26 @@ public class ColumnInfor
3030

3131
public bool IsJson { get; set; }
3232

33-
public IReadOnlyList<JsonPropertyWriter>? JsonPropertyWriters { get; init; }
33+
public IReadOnlyList<JsonProperty>? JsonProperties { get; init; }
3434

35-
public IReadOnlyDictionary<string, JsonPropertyWriter> GetFlattenedJsonPropertyWriters()
36-
{
37-
if (JsonPropertyWriters == null || JsonPropertyWriters.Count == 0)
38-
{
39-
return new Dictionary<string, JsonPropertyWriter>();
40-
}
41-
42-
var result = new Dictionary<string, JsonPropertyWriter>();
43-
FlattenJsonPropertyWriters(JsonPropertyWriters, result);
44-
return result;
45-
}
46-
47-
private static void FlattenJsonPropertyWriters(IReadOnlyList<JsonPropertyWriter> writers, Dictionary<string, JsonPropertyWriter> result)
48-
{
49-
foreach (var writer in writers)
50-
{
51-
result[writer.FullClrPropertyName] = writer;
52-
53-
if (writer.IsNestedComplexType)
54-
{
55-
FlattenJsonPropertyWriters(writer.NestedProperties, result);
56-
}
57-
}
58-
}
35+
public IReadOnlyDictionary<string, JsonProperty> FlattenedJsonProperties { get; init; }
5936
}
6037

61-
public class JsonPropertyWriter
38+
public class JsonProperty
6239
{
6340
public string JsonPropertyName { get; init; }
6441

6542
public string ClrPropertyName { get; init; }
6643

67-
public string FullJsonPath { get; init; }
44+
public string FullJsonPropertyName { get; init; }
6845

6946
public string FullClrPropertyName { get; init; }
7047

7148
public Type PropertyType { get; init; }
7249

7350
public JsonValueReaderWriter? ReaderWriter { get; init; }
7451

75-
public IReadOnlyList<JsonPropertyWriter>? NestedProperties { get; init; }
52+
public IReadOnlyList<JsonProperty>? NestedProperties { get; init; }
7653

7754
public bool IsNestedComplexType => NestedProperties != null && NestedProperties.Count > 0;
7855

@@ -95,7 +72,7 @@ public void WriteValue(Utf8JsonWriter writer, object? value)
9572
}
9673
}
9774

98-
public static string Serialize(object obj, IReadOnlyList<JsonPropertyWriter> writers)
75+
public static string Serialize(object obj, IReadOnlyList<JsonProperty> writers)
9976
{
10077
using var stream = new MemoryStream();
10178
using var writer = new Utf8JsonWriter(stream);
@@ -106,7 +83,7 @@ public static string Serialize(object obj, IReadOnlyList<JsonPropertyWriter> wri
10683
return Encoding.UTF8.GetString(stream.ToArray());
10784
}
10885

109-
private static void WriteObject(Utf8JsonWriter writer, object obj, IReadOnlyList<JsonPropertyWriter> propertyWriters)
86+
private static void WriteObject(Utf8JsonWriter writer, object obj, IReadOnlyList<JsonProperty> propertyWriters)
11087
{
11188
writer.WriteStartObject();
11289

@@ -139,4 +116,29 @@ private static void WriteObject(Utf8JsonWriter writer, object obj, IReadOnlyList
139116

140117
writer.WriteEndObject();
141118
}
119+
120+
public static IReadOnlyDictionary<string, JsonProperty> FlattenJsonProperties(IReadOnlyList<JsonProperty>? jsonProperties)
121+
{
122+
if (jsonProperties == null || jsonProperties.Count == 0)
123+
{
124+
return new Dictionary<string, JsonProperty>();
125+
}
126+
127+
var result = new Dictionary<string, JsonProperty>();
128+
FlattenJsonProperties(jsonProperties, result);
129+
return result;
130+
}
131+
132+
private static void FlattenJsonProperties(IReadOnlyList<JsonProperty> jsonProperties, Dictionary<string, JsonProperty> result)
133+
{
134+
foreach (var jsonProperty in jsonProperties)
135+
{
136+
result[jsonProperty.FullClrPropertyName] = jsonProperty;
137+
138+
if (jsonProperty.IsNestedComplexType)
139+
{
140+
FlattenJsonProperties(jsonProperty.NestedProperties, result);
141+
}
142+
}
143+
}
142144
}

0 commit comments

Comments
 (0)