From 7745abb6922eac05c256f32664d5e09ab6f865c3 Mon Sep 17 00:00:00 2001
From: "dotnet-maestro[bot]"
<42748379+dotnet-maestro[bot]@users.noreply.github.com>
Date: Fri, 18 Aug 2023 18:43:09 +0000
Subject: [PATCH 1/5] Update dependencies from https://github.com/dotnet/arcade
build 20230817.3 (#31506)
[release/8.0] Update dependencies from dotnet/arcade
---
eng/Version.Details.xml | 12 ++++++------
eng/Versions.props | 2 +-
eng/common/native/init-compiler.sh | 2 +-
eng/common/sdl/trim-assets-version.ps1 | 2 +-
eng/common/templates/job/execute-sdl.yml | 5 +++++
global.json | 4 ++--
6 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index 7e15b29ef93..66d86aebc66 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -56,17 +56,17 @@
-
+
https://github.com/dotnet/arcade
- 46ff142f43e887d5f9a4d87ef39d72166f61db8d
+ 7837a0b504ed9a598daebd50f20520ccda5fe2b1
-
+
https://github.com/dotnet/arcade
- 46ff142f43e887d5f9a4d87ef39d72166f61db8d
+ 7837a0b504ed9a598daebd50f20520ccda5fe2b1
-
+
https://github.com/dotnet/arcade
- 46ff142f43e887d5f9a4d87ef39d72166f61db8d
+ 7837a0b504ed9a598daebd50f20520ccda5fe2b1
diff --git a/eng/Versions.props b/eng/Versions.props
index 1f424978954..0354c063169 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -31,7 +31,7 @@
8.0.0-rc.1.23402.2
- 8.0.0-beta.23415.4
+ 8.0.0-beta.23417.3
diff --git a/eng/common/native/init-compiler.sh b/eng/common/native/init-compiler.sh
index 517401b688b..f5c1ec7eafe 100644
--- a/eng/common/native/init-compiler.sh
+++ b/eng/common/native/init-compiler.sh
@@ -63,7 +63,7 @@ if [ -z "$CLR_CC" ]; then
# Set default versions
if [ -z "$majorVersion" ]; then
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
- if [ "$compiler" = "clang" ]; then versions="16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5"
+ if [ "$compiler" = "clang" ]; then versions="17 16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5"
elif [ "$compiler" = "gcc" ]; then versions="13 12 11 10 9 8 7 6 5 4.9"; fi
for version in $versions; do
diff --git a/eng/common/sdl/trim-assets-version.ps1 b/eng/common/sdl/trim-assets-version.ps1
index d8cfec910c7..a2e00487704 100644
--- a/eng/common/sdl/trim-assets-version.ps1
+++ b/eng/common/sdl/trim-assets-version.ps1
@@ -25,7 +25,7 @@ function Install-VersionTools-Cli {
Write-Host "Installing the package '$CliToolName' with a version of '$version' ..."
$feed = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json"
- $argumentList = @("tool", "install", "--local", "$CliToolName", "--add-source $feed", "--no-cache", "--version $Version")
+ $argumentList = @("tool", "install", "--local", "$CliToolName", "--add-source $feed", "--no-cache", "--version $Version", "--create-manifest-if-needed")
Start-Process "$dotnet" -Verbose -ArgumentList $argumentList -NoNewWindow -Wait
}
diff --git a/eng/common/templates/job/execute-sdl.yml b/eng/common/templates/job/execute-sdl.yml
index 7aabaa18017..7870f93bc17 100644
--- a/eng/common/templates/job/execute-sdl.yml
+++ b/eng/common/templates/job/execute-sdl.yml
@@ -105,6 +105,11 @@ jobs:
downloadPath: $(Build.ArtifactStagingDirectory)\artifacts
checkDownloadedFiles: true
+ - powershell: eng/common/sdl/trim-assets-version.ps1
+ -InputPath $(Build.ArtifactStagingDirectory)\artifacts
+ displayName: Trim the version from the NuGet packages
+ continueOnError: ${{ parameters.sdlContinueOnError }}
+
- powershell: eng/common/sdl/extract-artifact-packages.ps1
-InputPath $(Build.ArtifactStagingDirectory)\artifacts\BlobArtifacts
-ExtractPath $(Build.ArtifactStagingDirectory)\artifacts\BlobArtifacts
diff --git a/global.json b/global.json
index d75403af982..3c532609fdc 100644
--- a/global.json
+++ b/global.json
@@ -13,7 +13,7 @@
}
},
"msbuild-sdks": {
- "Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23415.4",
- "Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23415.4"
+ "Microsoft.DotNet.Arcade.Sdk": "8.0.0-beta.23417.3",
+ "Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23417.3"
}
}
From 336d56044b536ff02d13c6f2454eaab3a5aa9410 Mon Sep 17 00:00:00 2001
From: "dotnet-maestro[bot]"
<42748379+dotnet-maestro[bot]@users.noreply.github.com>
Date: Fri, 18 Aug 2023 19:02:32 +0000
Subject: [PATCH 2/5] [release/8.0] Update dependencies from dotnet/runtime
(#31498)
[release/8.0] Update dependencies from dotnet/runtime
- Update MemoryMarshal.Write after readonly changes in runtime
---
eng/Version.Details.xml | 52 +++++++++----------
eng/Versions.props | 26 +++++-----
.../SequentialGuidValueGenerator.cs | 2 +-
3 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index 66d86aebc66..dfece0ac7b3 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -1,58 +1,58 @@
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
-
+
https://github.com/dotnet/runtime
- 0d6d6c343556d8aaae49347c82b09281f8968196
+ f7df78f4c9b3944d1b937b264601d7b5da55f3ab
diff --git a/eng/Versions.props b/eng/Versions.props
index 0354c063169..83437b974bb 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -16,19 +16,19 @@
False
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
- 8.0.0-rc.1.23402.2
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23417.23
8.0.0-beta.23417.3
diff --git a/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs b/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs
index da016dfa442..569de845e67 100644
--- a/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs
+++ b/src/EFCore/ValueGeneration/SequentialGuidValueGenerator.cs
@@ -40,7 +40,7 @@ public override Guid Next(EntityEntry entry)
Check.DebugAssert(succeeded, "Could not write Guid to Span");
var incrementedCounter = Interlocked.Increment(ref _counter);
Span counterBytes = stackalloc byte[sizeof(long)];
- MemoryMarshal.Write(counterBytes, ref incrementedCounter);
+ MemoryMarshal.Write(counterBytes, in incrementedCounter);
if (!BitConverter.IsLittleEndian)
{
From 221ea0b3a839aea59478ac9c912c8af3246ec8d3 Mon Sep 17 00:00:00 2001
From: "dotnet-maestro[bot]"
<42748379+dotnet-maestro[bot]@users.noreply.github.com>
Date: Sat, 19 Aug 2023 05:19:01 +0000
Subject: [PATCH 3/5] Update dependencies from
https://github.com/dotnet/runtime build 20230818.14 (#31508)
[release/8.0] Update dependencies from dotnet/runtime
---
eng/Version.Details.xml | 52 ++++++++++++++++++++---------------------
eng/Versions.props | 26 ++++++++++-----------
2 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index dfece0ac7b3..d6f68eb4178 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -1,58 +1,58 @@
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
-
+
https://github.com/dotnet/runtime
- f7df78f4c9b3944d1b937b264601d7b5da55f3ab
+ 90b92bb265a412592c4c152983d7b30c92236dbe
diff --git a/eng/Versions.props b/eng/Versions.props
index 83437b974bb..ac8e47ae423 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -16,19 +16,19 @@
False
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
- 8.0.0-rc.2.23417.23
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
+ 8.0.0-rc.2.23418.14
8.0.0-beta.23417.3
From 4a976b7406ea4e0b408cc9ac4dc1f9618bba104b Mon Sep 17 00:00:00 2001
From: Shay Rojansky
Date: Sun, 20 Aug 2023 11:55:24 +0200
Subject: [PATCH 4/5] Add some enum generic constraints (#31515)
---
.../Json/JsonSignedEnumReaderWriter.cs | 1 +
.../Json/JsonUnsignedEnumReaderWriter.cs | 1 +
.../Json/JsonWarningEnumReaderWriter.cs | 2 +-
.../ValueConversion/EnumToNumberConverter.cs | 2 +-
.../ValueConversion/EnumToStringConverter.cs | 2 +-
.../Internal/StringEnumConverter.cs | 2 +-
.../ValueConversion/StringToEnumConverter.cs | 2 +-
.../Storage/EnumToNumberConverterTest.cs | 20 -------------------
.../Storage/EnumToStringConverterTest.cs | 10 ----------
.../Storage/StringToEnumConverterTest.cs | 10 ----------
10 files changed, 7 insertions(+), 45 deletions(-)
diff --git a/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs b/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs
index bf0651b1188..4870dc7ae2f 100644
--- a/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs
+++ b/src/EFCore/Storage/Json/JsonSignedEnumReaderWriter.cs
@@ -9,6 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
/// Reads and writes JSON for values backed by a signed integer.
///
public sealed class JsonSignedEnumReaderWriter : JsonValueReaderWriter
+ where TEnum : struct, Enum
{
///
/// The singleton instance of this stateless reader/writer.
diff --git a/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs b/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs
index a3ff3d9e9fb..a2ee0b607bf 100644
--- a/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs
+++ b/src/EFCore/Storage/Json/JsonUnsignedEnumReaderWriter.cs
@@ -9,6 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
/// Reads and writes JSON for values backed by an unsigned integer.
///
public sealed class JsonUnsignedEnumReaderWriter : JsonValueReaderWriter
+ where TEnum : struct, Enum
{
///
/// The singleton instance of this stateless reader/writer.
diff --git a/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs b/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs
index 1a757576a3e..3e38ae9d11c 100644
--- a/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs
+++ b/src/EFCore/Storage/Json/JsonWarningEnumReaderWriter.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
/// happens, a warning is generated.
///
public sealed class JsonWarningEnumReaderWriter : JsonValueReaderWriter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// The singleton instance of this stateless reader/writer.
diff --git a/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs b/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs
index 611b3cd9b7e..01c66b0c971 100644
--- a/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/EnumToNumberConverter.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// See EF Core value converters for more information and examples.
///
public class EnumToNumberConverter : ValueConverter
- where TEnum : struct
+ where TEnum : struct, Enum
where TNumber : struct
{
// ReSharper disable once StaticMemberInGenericType
diff --git a/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs b/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs
index 60f16ed19e0..5deccdbe343 100644
--- a/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/EnumToStringConverter.cs
@@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// See EF Core value converters for more information and examples.
///
public class EnumToStringConverter : StringEnumConverter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// Creates a new instance of this converter. This converter does not preserve order.
diff --git a/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs b/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs
index 9b86ccc731b..fc2c8ec5703 100644
--- a/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/Internal/StringEnumConverter.cs
@@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
/// doing so can result in application failures when updating to a new Entity Framework Core release.
///
public class StringEnumConverter : ValueConverter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
diff --git a/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs b/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs
index 8d353ea0eab..2761f19bced 100644
--- a/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs
+++ b/src/EFCore/Storage/ValueConversion/StringToEnumConverter.cs
@@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.ValueConversion;
/// See EF Core value converters for more information and examples.
///
public class StringToEnumConverter : StringEnumConverter
- where TEnum : struct
+ where TEnum : struct, Enum
{
///
/// Creates a new instance of this converter. This converter does not preserve order.
diff --git a/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs b/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs
index 77a2491f156..64a432cb1f0 100644
--- a/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs
+++ b/test/EFCore.Tests/Storage/EnumToNumberConverterTest.cs
@@ -265,26 +265,6 @@ public void Can_convert_ulongs_to_enums()
Assert.Equal(default, converter(0));
}
- [ConditionalFact]
- public void Enum_to_integer_converter_throws_for_bad_types()
- {
- Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(EnumToNumberConverter).ShortDisplayName(),
- "Guid",
- "enum types"),
- Assert.Throws(
- () => new EnumToNumberConverter()).Message);
-
- Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(EnumToNumberConverter).ShortDisplayName(),
- "Guid",
- "'int', 'long', 'short', 'byte', 'uint', 'ulong', 'ushort', 'sbyte', 'double', 'float', 'decimal'"),
- Assert.Throws(
- () => new EnumToNumberConverter()).Message);
- }
-
private enum Beatles
{
John = 7,
diff --git a/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs b/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs
index c54501c3c0b..154164debfa 100644
--- a/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs
+++ b/test/EFCore.Tests/Storage/EnumToStringConverterTest.cs
@@ -77,16 +77,6 @@ public void Can_convert_strings_to_enums_object()
Assert.Null(converter(null));
}
- [ConditionalFact]
- public void Enum_to_string_converter_throws_for_bad_types()
- => Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(StringEnumConverter).ShortDisplayName(),
- "Guid",
- "enum types"),
- Assert.Throws(
- () => new EnumToStringConverter()).Message);
-
private enum Beatles
{
John = 7,
diff --git a/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs b/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs
index 4ea4bef7452..eaeaed6040b 100644
--- a/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs
+++ b/test/EFCore.Tests/Storage/StringToEnumConverterTest.cs
@@ -78,16 +78,6 @@ public void Can_convert_enums_to_strings_object()
Assert.Null(converter(null));
}
- [ConditionalFact]
- public void String_to_enum_converter_throws_for_bad_types()
- => Assert.Equal(
- CoreStrings.ConverterBadType(
- typeof(StringEnumConverter).ShortDisplayName(),
- "Guid",
- "enum types"),
- Assert.Throws(
- () => new StringToEnumConverter()).Message);
-
private enum Beatles
{
John = 7,
From 0d590c83031bfcbb5532a142a370e95661617797 Mon Sep 17 00:00:00 2001
From: Arthur Vickers
Date: Sun, 20 Aug 2023 13:36:10 +0100
Subject: [PATCH 5/5] Throw if required primitive collection is null when
saving changes (#31521)
---
.../Internal/InternalEntityEntry.cs | 8 ++++++++
src/EFCore/Properties/CoreStrings.Designer.cs | 8 ++++++++
src/EFCore/Properties/CoreStrings.resx | 3 +++
.../TestModels/JsonQuery/JsonEntityAllTypes.cs | 4 ++++
.../Update/JsonUpdateTestBase.cs | 15 +++++++++++++++
5 files changed, 38 insertions(+)
diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
index 823179109e8..b13479b77c2 100644
--- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
+++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs
@@ -1571,6 +1571,14 @@ public InternalEntityEntry PrepareToSave()
throw new InvalidOperationException(CoreStrings.UnknownKeyValue(entityType.DisplayName(), property.Name));
}
+
+ if (property.GetElementType() != null
+ && !property.IsNullable
+ && GetCurrentValue(property) == null)
+ {
+ throw new InvalidOperationException(
+ CoreStrings.NullRequiredPrimitiveCollection(EntityType.DisplayName(), property.Name));
+ }
}
}
else if (EntityState == EntityState.Modified)
diff --git a/src/EFCore/Properties/CoreStrings.Designer.cs b/src/EFCore/Properties/CoreStrings.Designer.cs
index ffe136f9bac..1d6d20162be 100644
--- a/src/EFCore/Properties/CoreStrings.Designer.cs
+++ b/src/EFCore/Properties/CoreStrings.Designer.cs
@@ -2159,6 +2159,14 @@ public static string NullableKey(object? entityType, object? property)
GetString("NullableKey", nameof(entityType), nameof(property)),
entityType, property);
+ ///
+ /// The primitive collection property '{type}.{property}' is configured as required (non-nullable) but has a null value when saving changes. Either mark the property as optional (nullable) or set a non-null value.
+ ///
+ public static string NullRequiredPrimitiveCollection(object? type, object? property)
+ => string.Format(
+ GetString("NullRequiredPrimitiveCollection", nameof(type), nameof(property)),
+ type, property);
+
///
/// The object has been removed from the model.
///
diff --git a/src/EFCore/Properties/CoreStrings.resx b/src/EFCore/Properties/CoreStrings.resx
index c56b0700f52..9ba2559fe40 100644
--- a/src/EFCore/Properties/CoreStrings.resx
+++ b/src/EFCore/Properties/CoreStrings.resx
@@ -1246,6 +1246,9 @@
A key on entity type '{entityType}' cannot contain the property '{property}' because it is nullable/optional. All properties on which a key is declared must be marked as non-nullable/required.
+
+ The primitive collection property '{type}.{property}' is configured as required (non-nullable) but has a null value when saving changes. Either mark the property as optional (nullable) or set a non-null value.
+
The object has been removed from the model.
diff --git a/test/EFCore.Relational.Specification.Tests/TestModels/JsonQuery/JsonEntityAllTypes.cs b/test/EFCore.Relational.Specification.Tests/TestModels/JsonQuery/JsonEntityAllTypes.cs
index 8ba714be5f4..fb821d4989d 100644
--- a/test/EFCore.Relational.Specification.Tests/TestModels/JsonQuery/JsonEntityAllTypes.cs
+++ b/test/EFCore.Relational.Specification.Tests/TestModels/JsonQuery/JsonEntityAllTypes.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.ObjectModel;
+using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Microsoft.EntityFrameworkCore.TestModels.JsonQuery;
@@ -73,7 +74,10 @@ public IList TestBooleanCollection
}
public byte[] TestByteCollection { get; set; }
+
+ [Required]
public List TestGuidCollection { get; set; }
+
public IList TestUnsignedInt16Collection { get; set; }
public uint[] TestUnsignedInt32Collection { get; set; }
public ObservableCollection TestUnsignedInt64Collection { get; set; }
diff --git a/test/EFCore.Relational.Specification.Tests/Update/JsonUpdateTestBase.cs b/test/EFCore.Relational.Specification.Tests/Update/JsonUpdateTestBase.cs
index abbf5190f4e..34523ea581f 100644
--- a/test/EFCore.Relational.Specification.Tests/Update/JsonUpdateTestBase.cs
+++ b/test/EFCore.Relational.Specification.Tests/Update/JsonUpdateTestBase.cs
@@ -2971,6 +2971,21 @@ public virtual Task Edit_single_property_relational_collection_of_nullable_enum_
Assert.False(result.NewCollectionSet);
});
+ [ConditionalFact]
+ public virtual async Task SaveChanges_throws_when_required_primitive_collection_is_null()
+ => await TestHelpers.ExecuteWithStrategyInTransactionAsync(
+ CreateContext,
+ UseTransaction,
+ async context =>
+ {
+ var entity = new JsonEntityAllTypes { TestGuidCollection = null };
+ context.Add(entity);
+
+ Assert.Equal(
+ CoreStrings.NullRequiredPrimitiveCollection(nameof(JsonEntityAllTypes), nameof(JsonEntityAllTypes.TestGuidCollection)),
+ (await Assert.ThrowsAsync(async () => await context.SaveChangesAsync())).Message);
+ });
+
public void UseTransaction(DatabaseFacade facade, IDbContextTransaction transaction)
=> facade.UseTransaction(transaction.GetDbTransaction());