-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to #21006 - Support a default value for non-nullable properties
Only for scalar properties when projecting Json-mapped entity. Only need to change code for Cosmos - relational already works in the desired way after the change to streaming (properties that are not encountered maintain their default value) We still throw exception if JSON contains explicit null where non-nullable scalar is expected. Fixes #21006
- Loading branch information
Showing
9 changed files
with
1,398 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/EFCore.Cosmos.FunctionalTests/Query/AdHocCosmosTestHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Net; | ||
using Microsoft.Azure.Cosmos; | ||
using Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Query; | ||
|
||
public class AdHocCosmosTestHelpers | ||
{ | ||
public static async Task CreateCustomEntityHelperAsync( | ||
Container container, | ||
string json, | ||
CancellationToken cancellationToken) | ||
{ | ||
var document = JObject.Parse(json); | ||
|
||
var stream = new MemoryStream(); | ||
await using var __ = stream.ConfigureAwait(false); | ||
var writer = new StreamWriter(stream, new UTF8Encoding(), bufferSize: 1024, leaveOpen: false); | ||
await using var ___ = writer.ConfigureAwait(false); | ||
using var jsonWriter = new JsonTextWriter(writer); | ||
|
||
CosmosClientWrapper.Serializer.Serialize(jsonWriter, document); | ||
await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false); | ||
|
||
var response = await container.CreateItemStreamAsync( | ||
stream, | ||
PartitionKey.None, | ||
requestOptions: null, | ||
cancellationToken) | ||
.ConfigureAwait(false); | ||
|
||
|
||
if (response.StatusCode != HttpStatusCode.Created) | ||
{ | ||
throw new InvalidOperationException($"Failed to create entitty (status code: {response.StatusCode}) for json: {json}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.