diff --git a/All.sln b/All.sln index 7020ff3db50..c30cbe2273b 100644 --- a/All.sln +++ b/All.sln @@ -120,6 +120,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.Sqlite.Functi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.AspNet.InMemory.FunctionalTests", "test\EFCore.AspNet.InMemory.FunctionalTests\EFCore.AspNet.InMemory.FunctionalTests.csproj", "{F1B2E5A0-8C74-414A-B262-353FEE325E9F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EFCore.Trimming.Tests", "test\EFCore.Trimming.Tests\EFCore.Trimming.Tests.csproj", "{933C8662-817C-4F45-B98B-6557E28F7BB1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -318,6 +320,10 @@ Global {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU {F1B2E5A0-8C74-414A-B262-353FEE325E9F}.Release|Any CPU.Build.0 = Release|Any CPU + {933C8662-817C-4F45-B98B-6557E28F7BB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {933C8662-817C-4F45-B98B-6557E28F7BB1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {933C8662-817C-4F45-B98B-6557E28F7BB1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {933C8662-817C-4F45-B98B-6557E28F7BB1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -371,6 +377,7 @@ Global {F956A344-5C8D-4015-A3BF-7A8304C58BE4} = {258D5057-81B9-40EC-A872-D21E27452749} {CC93C465-F5AC-4CB9-A064-3675955962F4} = {258D5057-81B9-40EC-A872-D21E27452749} {F1B2E5A0-8C74-414A-B262-353FEE325E9F} = {258D5057-81B9-40EC-A872-D21E27452749} + {933C8662-817C-4F45-B98B-6557E28F7BB1} = {258D5057-81B9-40EC-A872-D21E27452749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {285A5EB4-BCF4-40EB-B9E1-DF6DBCB5E705} diff --git a/Directory.Build.props b/Directory.Build.props index 62d58cd77b5..5e985fd1e50 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,6 +3,7 @@ True False + False diff --git a/azure-pipelines.yml b/azure-pipelines.yml index de093168e65..05a6d074f89 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,6 +1,8 @@ variables: - name: _BuildConfig value: Release + - name: _BuildTargetFramework + value: net6.0 - name: _TeamName value: AspNetCore - name: DOTNET_SKIP_FIRST_TIME_EXPERIENCE @@ -100,6 +102,10 @@ stages: env: Test__Cosmos__DefaultConnection: $(_CosmosConnectionUrl) name: Build + - script: | + .dotnet\dotnet publish --configuration $(_BuildConfig) --runtime win-x64 --self-contained test\EFCore.Trimming.Tests + artifacts\bin\EFCore.Trimming.Tests\$(_BuildConfig)\$(_BuildTargetFramework)\win-x64\publish\EFCore.Trimming.Tests.exe + displayName: Test trimming - task: PublishBuildArtifacts@1 displayName: Upload TestResults condition: always() diff --git a/eng/helix.proj b/eng/helix.proj index 7f9a2b8eec0..22f976a4549 100644 --- a/eng/helix.proj +++ b/eng/helix.proj @@ -50,6 +50,11 @@ + + + + + net6.0 netcoreapp2.0 diff --git a/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs b/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs index 44afcde741c..4cc9ffd2ddf 100644 --- a/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs +++ b/src/EFCore.Cosmos/Extensions/CosmosQueryableExtensions.cs @@ -18,7 +18,7 @@ namespace Microsoft.EntityFrameworkCore; public static class CosmosQueryableExtensions { internal static readonly MethodInfo WithPartitionKeyMethodInfo - = typeof(CosmosQueryableExtensions).GetRequiredDeclaredMethod(nameof(WithPartitionKey)); + = typeof(CosmosQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(WithPartitionKey))!; /// /// Specify the partition key for partition used for the query. Required when using diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosStringMethodTranslator.cs b/src/EFCore.Cosmos/Query/Internal/CosmosStringMethodTranslator.cs index cf039c92298..5215e82274e 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosStringMethodTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosStringMethodTranslator.cs @@ -12,52 +12,52 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.Query.Internal; public class CosmosStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo IndexOfMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string) })!; private static readonly MethodInfo IndexOfMethodInfoWithStartingPosition - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string), typeof(int) })!; private static readonly MethodInfo ReplaceMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Replace), typeof(string), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Replace), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo ContainsMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Contains), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) })!; private static readonly MethodInfo StartsWithMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.StartsWith), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) })!; private static readonly MethodInfo EndsWithMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.EndsWith), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) })!; private static readonly MethodInfo ToLowerMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.ToLower), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.ToLower), Array.Empty())!; private static readonly MethodInfo ToUpperMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.ToUpper), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.ToUpper), Array.Empty())!; private static readonly MethodInfo TrimStartMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), Array.Empty())!; private static readonly MethodInfo TrimEndMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), Array.Empty())!; private static readonly MethodInfo TrimMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), Array.Empty())!; private static readonly MethodInfo TrimStartMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char[]) })!; private static readonly MethodInfo TrimEndMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char[]) })!; private static readonly MethodInfo TrimMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char[]) })!; private static readonly MethodInfo SubstringMethodInfoWithOneArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int) })!; private static readonly MethodInfo SubstringMethodInfoWithTwoArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int), typeof(int) })!; private static readonly MethodInfo FirstOrDefaultMethodInfoWithoutArgs = typeof(Enumerable).GetRuntimeMethods().Single( @@ -70,19 +70,19 @@ private static readonly MethodInfo LastOrDefaultMethodInfoWithoutArgs && m.GetParameters().Length == 1).MakeGenericMethod(typeof(char)); private static readonly MethodInfo StringConcatWithTwoArguments = - typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string)); + typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo StringConcatWithThreeArguments = - typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string), typeof(string)); + typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string), typeof(string) })!; private static readonly MethodInfo StringConcatWithFourArguments = - typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string), typeof(string), typeof(string)); + typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string), typeof(string), typeof(string) })!; private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentInstance - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Equals), typeof(string), typeof(StringComparison)); + = typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(StringComparison) })!; private static readonly MethodInfo StringComparisonWithComparisonTypeArgumentStatic - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Equals), typeof(string), typeof(string), typeof(StringComparison)); + = typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(string), typeof(StringComparison) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Cosmos/Query/Internal/MathTranslator.cs b/src/EFCore.Cosmos/Query/Internal/MathTranslator.cs index 509ad458839..2460a39fc94 100644 --- a/src/EFCore.Cosmos/Query/Internal/MathTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/MathTranslator.cs @@ -13,60 +13,60 @@ public class MathTranslator : IMethodCallTranslator { private static readonly Dictionary SupportedMethodTranslations = new() { - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(decimal)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(double)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(float)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(int)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(long)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(sbyte)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(short)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Ceiling), typeof(decimal)), "CEILING" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Ceiling), typeof(double)), "CEILING" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Floor), typeof(decimal)), "FLOOR" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Floor), typeof(double)), "FLOOR" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Pow), typeof(double), typeof(double)), "POWER" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Exp), typeof(double)), "EXP" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Log10), typeof(double)), "LOG10" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Log), typeof(double)), "LOG" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Log), typeof(double), typeof(double)), "LOG" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sqrt), typeof(double)), "SQRT" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Acos), typeof(double)), "ACOS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Asin), typeof(double)), "ASIN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Atan), typeof(double)), "ATAN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Atan2), typeof(double), typeof(double)), "ATN2" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Cos), typeof(double)), "COS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sin), typeof(double)), "SIN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Tan), typeof(double)), "TAN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(decimal)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(double)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(float)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(int)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(long)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(sbyte)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(short)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Truncate), typeof(decimal)), "TRUNC" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Truncate), typeof(double)), "TRUNC" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), typeof(decimal)), "ROUND" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), typeof(double)), "ROUND" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Abs), typeof(float)), "ABS" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Ceiling), typeof(float)), "CEILING" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Floor), typeof(float)), "FLOOR" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Pow), typeof(float), typeof(float)), "POWER" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Exp), typeof(float)), "EXP" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Log10), typeof(float)), "LOG10" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Log), typeof(float)), "LOG" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Log), typeof(float), typeof(float)), "LOG" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Sqrt), typeof(float)), "SQRT" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Acos), typeof(float)), "ACOS" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Asin), typeof(float)), "ASIN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Atan), typeof(float)), "ATAN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Atan2), typeof(float), typeof(float)), "ATN2" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Cos), typeof(float)), "COS" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Sin), typeof(float)), "SIN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Tan), typeof(float)), "TAN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Sign), typeof(float)), "SIGN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Truncate), typeof(float)), "TRUNC" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Round), typeof(float)), "ROUND" } + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(decimal) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(double) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(float) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(int) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(long) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(sbyte) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(short) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Ceiling), new[] { typeof(decimal) })!, "CEILING" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Ceiling), new[] { typeof(double) })!, "CEILING" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Floor), new[] { typeof(decimal) })!, "FLOOR" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Floor), new[] { typeof(double) })!, "FLOOR" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Pow), new[] { typeof(double), typeof(double) })!, "POWER" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Exp), new[] { typeof(double) })!, "EXP" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Log10), new[] { typeof(double) })!, "LOG10" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double) })!, "LOG" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double), typeof(double) })!, "LOG" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sqrt), new[] { typeof(double) })!, "SQRT" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Acos), new[] { typeof(double) })!, "ACOS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Asin), new[] { typeof(double) })!, "ASIN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Atan), new[] { typeof(double) })!, "ATAN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Atan2), new[] { typeof(double), typeof(double) })!, "ATN2" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Cos), new[] { typeof(double) })!, "COS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sin), new[] { typeof(double) })!, "SIN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Tan), new[] { typeof(double) })!, "TAN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(decimal) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(double) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(float) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(int) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(long) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(sbyte) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(short) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Truncate), new[] { typeof(decimal) })!, "TRUNC" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Truncate), new[] { typeof(double) })!, "TRUNC" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(decimal) })!, "ROUND" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(double) })!, "ROUND" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "ABS" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Ceiling), new[] { typeof(float) })!, "CEILING" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Floor), new[] { typeof(float) })!, "FLOOR" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Pow), new[] { typeof(float), typeof(float) })!, "POWER" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Exp), new[] { typeof(float) })!, "EXP" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Log10), new[] { typeof(float) })!, "LOG10" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Log), new[] { typeof(float) })!, "LOG" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Log), new[] { typeof(float), typeof(float) })!, "LOG" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Sqrt), new[] { typeof(float) })!, "SQRT" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Acos), new[] { typeof(float) })!, "ACOS" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Asin), new[] { typeof(float) })!, "ASIN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Atan), new[] { typeof(float) })!, "ATAN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Atan2), new[] { typeof(float), typeof(float) })!, "ATN2" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Cos), new[] { typeof(float) })!, "COS" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Sin), new[] { typeof(float) })!, "SIN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Tan), new[] { typeof(float) })!, "TAN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Sign), new[] { typeof(float) })!, "SIGN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Truncate), new[] { typeof(float) })!, "TRUNC" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Round), new[] { typeof(float) })!, "ROUND" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs index d42eec8d14e..981cffe17a9 100644 --- a/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs +++ b/src/EFCore.Design/Migrations/Design/CSharpSnapshotGenerator.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design; public class CSharpSnapshotGenerator : ICSharpSnapshotGenerator { private static readonly MethodInfo HasAnnotationMethodInfo - = typeof(ModelBuilder).GetRequiredRuntimeMethod(nameof(ModelBuilder.HasAnnotation), typeof(string), typeof(string)); + = typeof(ModelBuilder).GetRuntimeMethod(nameof(ModelBuilder.HasAnnotation), new[] { typeof(string), typeof(string) })!; /// /// Initializes a new instance of the class. diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index 4c5d22730f5..11aa5997513 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -23,28 +23,28 @@ public class InMemoryExpressionTranslatingExpressionVisitor : ExpressionVisitor private static readonly MemberInfo ValueBufferIsEmpty = typeof(ValueBuffer).GetMember(nameof(ValueBuffer.IsEmpty))[0]; private static readonly MethodInfo ParameterValueExtractorMethod = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterValueExtractor)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterValueExtractor))!; private static readonly MethodInfo ParameterListValueExtractorMethod = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterListValueExtractor)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterListValueExtractor))!; private static readonly MethodInfo GetParameterValueMethodInfo = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(GetParameterValue)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(GetParameterValue))!; - private static readonly MethodInfo LikeMethodInfo = typeof(DbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(DbFunctionsExtensions.Like), typeof(DbFunctions), typeof(string), typeof(string)); + private static readonly MethodInfo LikeMethodInfo = typeof(DbFunctionsExtensions).GetRuntimeMethod( + nameof(DbFunctionsExtensions.Like), new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; - private static readonly MethodInfo LikeMethodInfoWithEscape = typeof(DbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(DbFunctionsExtensions.Like), typeof(DbFunctions), typeof(string), typeof(string), typeof(string)); + private static readonly MethodInfo LikeMethodInfoWithEscape = typeof(DbFunctionsExtensions).GetRuntimeMethod( + nameof(DbFunctionsExtensions.Like), new[] { typeof(DbFunctions), typeof(string), typeof(string), typeof(string) })!; - private static readonly MethodInfo RandomMethodInfo = typeof(DbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(DbFunctionsExtensions.Random), typeof(DbFunctions)); + private static readonly MethodInfo RandomMethodInfo = typeof(DbFunctionsExtensions).GetRuntimeMethod( + nameof(DbFunctionsExtensions.Random), new[] { typeof(DbFunctions) })!; - private static readonly MethodInfo RandomNextDoubleMethodInfo = typeof(Random).GetRequiredRuntimeMethod( - nameof(Random.NextDouble), Array.Empty()); + private static readonly MethodInfo RandomNextDoubleMethodInfo = typeof(Random).GetRuntimeMethod( + nameof(Random.NextDouble), Type.EmptyTypes)!; private static readonly MethodInfo InMemoryLikeMethodInfo = - typeof(InMemoryExpressionTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InMemoryLike)); + typeof(InMemoryExpressionTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InMemoryLike))!; // Regex special chars defined here: // https://msdn.microsoft.com/en-us/library/4edbef7e(v=vs.110).aspx diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs index 47efb59d618..31b864eb51f 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryExpression.cs @@ -18,7 +18,7 @@ private static readonly ConstructorInfo ValueBufferConstructor = typeof(ValueBuffer).GetConstructors().Single(ci => ci.GetParameters().Length == 1); private static readonly PropertyInfo ValueBufferCountMemberInfo - = typeof(ValueBuffer).GetRequiredProperty(nameof(ValueBuffer.Count)); + = typeof(ValueBuffer).GetTypeInfo().GetProperty(nameof(ValueBuffer.Count))!; private static readonly MethodInfo LeftJoinMethodInfo = typeof(InMemoryQueryExpression).GetTypeInfo() .GetDeclaredMethods(nameof(LeftJoin)).Single(mi => mi.GetParameters().Length == 6); @@ -889,8 +889,8 @@ private Expression AddJoin( bool innerNullable) { var transparentIdentifierType = TransparentIdentifierFactory.Create(outerShaperExpression.Type, innerShaperExpression.Type); - var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var outerClientEval = _clientProjections.Count > 0; var innerClientEval = innerQueryExpression._clientProjections.Count > 0; var resultSelectorExpressions = new List(); diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs index 418a47493f3..00f06a3641f 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryQueryableMethodTranslatingExpressionVisitor.cs @@ -1145,7 +1145,7 @@ private Expression ExpandSharedTypeEntities(InMemoryQueryExpression queryExpress private sealed class SharedTypeEntityExpandingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo ObjectEqualsMethodInfo - = typeof(object).GetRequiredRuntimeMethod(nameof(object.Equals), typeof(object), typeof(object)); + = typeof(object).GetRuntimeMethod(nameof(object.Equals), new[] { typeof(object), typeof(object) })!; private readonly InMemoryExpressionTranslatingExpressionVisitor _expressionTranslator; @@ -1352,7 +1352,7 @@ private static Expression AccessField( Type transparentIdentifierType, Expression targetExpression, string fieldName) - => Expression.Field(targetExpression, transparentIdentifierType.GetRequiredDeclaredField(fieldName)); + => Expression.Field(targetExpression, transparentIdentifierType.GetTypeInfo().GetDeclaredField(fieldName)!); private ShapedQueryExpression? TranslateScalarAggregate( ShapedQueryExpression source, diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs index 63ce00d833d..fddb9841612 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.ShaperExpressionProcessingExpressionVisitor.cs @@ -10,19 +10,19 @@ public partial class InMemoryShapedQueryCompilingExpressionVisitor private sealed class ShaperExpressionProcessingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo IncludeReferenceMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(IncludeReference)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(IncludeReference))!; private static readonly MethodInfo IncludeCollectionMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(IncludeCollection)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(IncludeCollection))!; private static readonly MethodInfo MaterializeCollectionMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(MaterializeCollection)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(MaterializeCollection))!; private static readonly MethodInfo MaterializeSingleResultMethodInfo - = typeof(ShaperExpressionProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(MaterializeSingleResult)); + = typeof(ShaperExpressionProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(MaterializeSingleResult))!; private static readonly MethodInfo CollectionAccessorAddMethodInfo - = typeof(IClrCollectionAccessor).GetRequiredDeclaredMethod(nameof(IClrCollectionAccessor.Add)); + = typeof(IClrCollectionAccessor).GetTypeInfo().GetDeclaredMethod(nameof(IClrCollectionAccessor.Add))!; private readonly InMemoryShapedQueryCompilingExpressionVisitor _inMemoryShapedQueryCompilingExpressionVisitor; private readonly bool _tracking; diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs index f269e02b94c..20983a58665 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryShapedQueryCompilingExpressionVisitor.cs @@ -71,7 +71,7 @@ protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQuery } private static readonly MethodInfo TableMethodInfo - = typeof(InMemoryShapedQueryCompilingExpressionVisitor).GetRequiredDeclaredMethod(nameof(Table)); + = typeof(InMemoryShapedQueryCompilingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(Table))!; private static IEnumerable Table( QueryContext queryContext, diff --git a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs index 196c2bb4086..a091fb79db8 100644 --- a/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs +++ b/src/EFCore.Relational/Design/AnnotationCodeGenerator.cs @@ -36,76 +36,76 @@ public class AnnotationCodeGenerator : IAnnotationCodeGenerator #region MethodInfos private static readonly MethodInfo ModelHasDefaultSchemaMethodInfo - = typeof(RelationalModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalModelBuilderExtensions.HasDefaultSchema), typeof(ModelBuilder), typeof(string)); + = typeof(RelationalModelBuilderExtensions).GetRuntimeMethod( + nameof(RelationalModelBuilderExtensions.HasDefaultSchema), new[] { typeof(ModelBuilder), typeof(string) })!; private static readonly MethodInfo ModelUseCollationMethodInfo - = typeof(RelationalModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalModelBuilderExtensions.UseCollation), typeof(ModelBuilder), typeof(string)); + = typeof(RelationalModelBuilderExtensions).GetRuntimeMethod( + nameof(RelationalModelBuilderExtensions.UseCollation), new[] { typeof(ModelBuilder), typeof(string) })!; private static readonly MethodInfo EntityTypeHasCommentMethodInfo - = typeof(RelationalEntityTypeBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalEntityTypeBuilderExtensions.HasComment), typeof(EntityTypeBuilder), typeof(string)); + = typeof(RelationalEntityTypeBuilderExtensions).GetRuntimeMethod( + nameof(RelationalEntityTypeBuilderExtensions.HasComment), new[] { typeof(EntityTypeBuilder), typeof(string) })!; private static readonly MethodInfo PropertyHasColumnNameMethodInfo - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasColumnName), typeof(PropertyBuilder), typeof(string)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasColumnName), new[] { typeof(PropertyBuilder), typeof(string) })!; private static readonly MethodInfo PropertyHasColumnOrderMethodInfo - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasColumnOrder), typeof(PropertyBuilder), typeof(int?)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasColumnOrder), new[] { typeof(PropertyBuilder), typeof(int?) })!; private static readonly MethodInfo PropertyHasDefaultValueSqlMethodInfo1 - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql), typeof(PropertyBuilder)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql), new[] { typeof(PropertyBuilder) })!; private static readonly MethodInfo PropertyHasDefaultValueSqlMethodInfo2 - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql), typeof(PropertyBuilder), typeof(string)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql), new[] { typeof(PropertyBuilder), typeof(string) })!; private static readonly MethodInfo PropertyHasComputedColumnSqlMethodInfo1 - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), typeof(PropertyBuilder)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), new[] { typeof(PropertyBuilder) })!; private static readonly MethodInfo PropertyHasComputedColumnSqlMethodInfo2 - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), typeof(PropertyBuilder), typeof(string)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), new[] { typeof(PropertyBuilder), typeof(string) })!; private static readonly MethodInfo HasComputedColumnSqlMethodInfo3 - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), typeof(PropertyBuilder), typeof(string), typeof(bool)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), new[] { typeof(PropertyBuilder), typeof(string), typeof(bool) })!; private static readonly MethodInfo PropertyIsFixedLengthMethodInfo - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.IsFixedLength), typeof(PropertyBuilder), typeof(bool)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.IsFixedLength), new[] { typeof(PropertyBuilder), typeof(bool) })!; private static readonly MethodInfo PropertyHasCommentMethodInfo - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.HasComment), typeof(PropertyBuilder), typeof(string)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.HasComment), new[] { typeof(PropertyBuilder), typeof(string) })!; private static readonly MethodInfo PropertyUseCollationMethodInfo - = typeof(RelationalPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalPropertyBuilderExtensions.UseCollation), typeof(PropertyBuilder), typeof(string)); + = typeof(RelationalPropertyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalPropertyBuilderExtensions.UseCollation), new[] { typeof(PropertyBuilder), typeof(string) })!; private static readonly MethodInfo KeyHasNameMethodInfo - = typeof(RelationalKeyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalKeyBuilderExtensions.HasName), typeof(KeyBuilder), typeof(string)); + = typeof(RelationalKeyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalKeyBuilderExtensions.HasName), new[] { typeof(KeyBuilder), typeof(string) })!; private static readonly MethodInfo ReferenceReferenceHasConstraintNameMethodInfo - = typeof(RelationalForeignKeyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalForeignKeyBuilderExtensions.HasConstraintName), typeof(ReferenceReferenceBuilder), typeof(string)); + = typeof(RelationalForeignKeyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalForeignKeyBuilderExtensions.HasConstraintName), new[] { typeof(ReferenceReferenceBuilder), typeof(string) })!; private static readonly MethodInfo ReferenceCollectionHasConstraintNameMethodInfo - = typeof(RelationalForeignKeyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalForeignKeyBuilderExtensions.HasConstraintName), typeof(ReferenceCollectionBuilder), typeof(string)); + = typeof(RelationalForeignKeyBuilderExtensions).GetRuntimeMethod( + nameof(RelationalForeignKeyBuilderExtensions.HasConstraintName), new[] { typeof(ReferenceCollectionBuilder), typeof(string) })!; private static readonly MethodInfo IndexHasDatabaseNameMethodInfo - = typeof(RelationalIndexBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalIndexBuilderExtensions.HasDatabaseName), typeof(IndexBuilder), typeof(string)); + = typeof(RelationalIndexBuilderExtensions).GetRuntimeMethod( + nameof(RelationalIndexBuilderExtensions.HasDatabaseName), new[] { typeof(IndexBuilder), typeof(string) })!; private static readonly MethodInfo IndexHasFilterNameMethodInfo - = typeof(RelationalIndexBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalIndexBuilderExtensions.HasFilter), typeof(IndexBuilder), typeof(string)); + = typeof(RelationalIndexBuilderExtensions).GetRuntimeMethod( + nameof(RelationalIndexBuilderExtensions.HasFilter), new[] { typeof(IndexBuilder), typeof(string) })!; #endregion MethodInfos diff --git a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs index 55fb2319a48..03670e2e7de 100644 --- a/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalQueryableExtensions.cs @@ -191,7 +191,7 @@ public static IQueryable AsSingleQuery( : source; internal static readonly MethodInfo AsSingleQueryMethodInfo - = typeof(RelationalQueryableExtensions).GetRequiredDeclaredMethod(nameof(AsSingleQuery)); + = typeof(RelationalQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsSingleQuery))!; /// /// Returns a new query which is configured to load the collections in the query results through separate database queries. @@ -223,5 +223,5 @@ public static IQueryable AsSplitQuery( : source; internal static readonly MethodInfo AsSplitQueryMethodInfo - = typeof(RelationalQueryableExtensions).GetRequiredDeclaredMethod(nameof(AsSplitQuery)); + = typeof(RelationalQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsSplitQuery))!; } diff --git a/src/EFCore.Relational/Query/IMethodCallTranslator.cs b/src/EFCore.Relational/Query/IMethodCallTranslator.cs index ac921239e36..13432daa93f 100644 --- a/src/EFCore.Relational/Query/IMethodCallTranslator.cs +++ b/src/EFCore.Relational/Query/IMethodCallTranslator.cs @@ -25,9 +25,6 @@ public interface IMethodCallTranslator /// SQL representations of . /// The query logger to use. /// A SQL translation of the . - // This is a 6.0.x hack to make trimming work, since the linker doesn't see our GetRequiredRuntimeMethod invocations below - // (see #26288) - [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Math))] SqlExpression? Translate( SqlExpression? instance, MethodInfo method, diff --git a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs index 8b923532278..eeef6da8c31 100644 --- a/src/EFCore.Relational/Query/Internal/CollateTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/CollateTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class CollateTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo - = typeof(RelationalDbFunctionsExtensions).GetRequiredMethod(nameof(RelationalDbFunctionsExtensions.Collate)); + = typeof(RelationalDbFunctionsExtensions).GetMethod(nameof(RelationalDbFunctionsExtensions.Collate))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs index 645947ca365..c9d03fc104f 100644 --- a/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/EnumHasFlagTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class EnumHasFlagTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo - = typeof(Enum).GetRequiredRuntimeMethod(nameof(Enum.HasFlag), typeof(Enum)); + = typeof(Enum).GetRuntimeMethod(nameof(Enum.HasFlag), new[] { typeof(Enum) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs index a73c56790a4..9685061d718 100644 --- a/src/EFCore.Relational/Query/Internal/LikeTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/LikeTranslator.cs @@ -14,12 +14,12 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class LikeTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo - = typeof(DbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(DbFunctionsExtensions.Like), typeof(DbFunctions), typeof(string), typeof(string)); + = typeof(DbFunctionsExtensions).GetRuntimeMethod( + nameof(DbFunctionsExtensions.Like), new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; private static readonly MethodInfo MethodInfoWithEscape - = typeof(DbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(DbFunctionsExtensions.Like), typeof(DbFunctions), typeof(string), typeof(string), typeof(string)); + = typeof(DbFunctionsExtensions).GetRuntimeMethod( + nameof(DbFunctionsExtensions.Like), new[] { typeof(DbFunctions), typeof(string), typeof(string), typeof(string) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Relational/Query/Internal/RandomTranslator.cs b/src/EFCore.Relational/Query/Internal/RandomTranslator.cs index bcfe0f5b280..5fc45186084 100644 --- a/src/EFCore.Relational/Query/Internal/RandomTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/RandomTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class RandomTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = - typeof(DbFunctionsExtensions).GetRequiredRuntimeMethod(nameof(DbFunctionsExtensions.Random), typeof(DbFunctions)); + typeof(DbFunctionsExtensions).GetRuntimeMethod(nameof(DbFunctionsExtensions.Random), new[] { typeof(DbFunctions) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs index 8e135846dfa..7ee095e5b72 100644 --- a/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/RelationalProjectionBindingExpressionVisitor.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class RelationalProjectionBindingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo GetParameterValueMethodInfo - = typeof(RelationalProjectionBindingExpressionVisitor).GetRequiredDeclaredMethod(nameof(GetParameterValue)); + = typeof(RelationalProjectionBindingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(GetParameterValue))!; private readonly RelationalQueryableMethodTranslatingExpressionVisitor _queryableMethodTranslatingExpressionVisitor; private readonly RelationalSqlTranslatingExpressionVisitor _sqlTranslator; diff --git a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs index 12202972284..e236779c89a 100644 --- a/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/StringMethodTranslator.cs @@ -14,17 +14,17 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class StringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo IsNullOrEmptyMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IsNullOrEmpty), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IsNullOrEmpty), new[] { typeof(string) })!; private static readonly MethodInfo ConcatMethodInfoTwoArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo ConcatMethodInfoThreeArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Concat), typeof(string), typeof(string), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Concat), new[] { typeof(string), typeof(string), typeof(string) })!; private static readonly MethodInfo ConcatMethodInfoFourArgs - = typeof(string).GetRequiredRuntimeMethod( - nameof(string.Concat), typeof(string), typeof(string), typeof(string), typeof(string)); + = typeof(string).GetRuntimeMethod( + nameof(string.Concat), new[] { typeof(string), typeof(string), typeof(string), typeof(string) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs index 27f76828361..619c463a438 100644 --- a/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs @@ -985,7 +985,7 @@ private Expression ExpandSharedTypeEntities(SelectExpression selectExpression, E private sealed class SharedTypeEntityExpandingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo ObjectEqualsMethodInfo - = typeof(object).GetRequiredRuntimeMethod(nameof(object.Equals), typeof(object), typeof(object)); + = typeof(object).GetRuntimeMethod(nameof(object.Equals), new[] { typeof(object), typeof(object) })!; private readonly RelationalSqlTranslatingExpressionVisitor _sqlTranslator; private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -1350,7 +1350,7 @@ private static Expression AccessField( Type transparentIdentifierType, Expression targetExpression, string fieldName) - => Expression.Field(targetExpression, transparentIdentifierType.GetRequiredDeclaredField(fieldName)); + => Expression.Field(targetExpression, transparentIdentifierType.GetTypeInfo().GetDeclaredField(fieldName)!); private static void HandleGroupByForAggregate(SelectExpression selectExpression, bool eraseProjection = false) { diff --git a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs index fa446fd3dd8..7dba5391654 100644 --- a/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalShapedQueryCompilingExpressionVisitor.ShaperProcessingExpressionVisitor.cs @@ -15,13 +15,13 @@ private sealed class ShaperProcessingExpressionVisitor : ExpressionVisitor { // Reading database values private static readonly MethodInfo IsDbNullMethod = - typeof(DbDataReader).GetRequiredRuntimeMethod(nameof(DbDataReader.IsDBNull), typeof(int)); + typeof(DbDataReader).GetRuntimeMethod(nameof(DbDataReader.IsDBNull), new[] { typeof(int) })!; public static readonly MethodInfo GetFieldValueMethod = - typeof(DbDataReader).GetRequiredRuntimeMethod(nameof(DbDataReader.GetFieldValue), typeof(int)); + typeof(DbDataReader).GetRuntimeMethod(nameof(DbDataReader.GetFieldValue), new[] { typeof(int) })!; private static readonly MethodInfo ThrowReadValueExceptionMethod = - typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ThrowReadValueException)); + typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ThrowReadValueException))!; // Coordinating results private static readonly MemberInfo ResultContextValuesMemberInfo @@ -32,43 +32,43 @@ private static readonly MemberInfo SingleQueryResultCoordinatorResultReadyMember // Performing collection materialization private static readonly MethodInfo IncludeReferenceMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(IncludeReference)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(IncludeReference))!; private static readonly MethodInfo InitializeIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeIncludeCollection))!; private static readonly MethodInfo PopulateIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateIncludeCollection))!; private static readonly MethodInfo InitializeSplitIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeSplitIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeSplitIncludeCollection))!; private static readonly MethodInfo PopulateSplitIncludeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitIncludeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitIncludeCollection))!; private static readonly MethodInfo PopulateSplitIncludeCollectionAsyncMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitIncludeCollectionAsync)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitIncludeCollectionAsync))!; private static readonly MethodInfo InitializeCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeCollection))!; private static readonly MethodInfo PopulateCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateCollection))!; private static readonly MethodInfo InitializeSplitCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(InitializeSplitCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(InitializeSplitCollection))!; private static readonly MethodInfo PopulateSplitCollectionMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitCollection)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitCollection))!; private static readonly MethodInfo PopulateSplitCollectionAsyncMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(PopulateSplitCollectionAsync)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(PopulateSplitCollectionAsync))!; private static readonly MethodInfo TaskAwaiterMethodInfo - = typeof(ShaperProcessingExpressionVisitor).GetRequiredDeclaredMethod(nameof(TaskAwaiter)); + = typeof(ShaperProcessingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(TaskAwaiter))!; private static readonly MethodInfo CollectionAccessorAddMethodInfo - = typeof(IClrCollectionAccessor).GetRequiredDeclaredMethod(nameof(IClrCollectionAccessor.Add)); + = typeof(IClrCollectionAccessor).GetTypeInfo().GetDeclaredMethod(nameof(IClrCollectionAccessor.Add))!; private readonly RelationalShapedQueryCompilingExpressionVisitor _parentVisitor; private readonly ISet? _tags; diff --git a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs index 4d5307a9663..90cac3419c2 100644 --- a/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs @@ -21,20 +21,20 @@ public class RelationalSqlTranslatingExpressionVisitor : ExpressionVisitor { private const string RuntimeParameterPrefix = QueryCompilationContext.QueryParameterPrefix + "entity_equality_"; - private static readonly MethodInfo ParameterValueExtractorMethid = - typeof(RelationalSqlTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterValueExtractor)); + private static readonly MethodInfo ParameterValueExtractorMethod = + typeof(RelationalSqlTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterValueExtractor))!; private static readonly MethodInfo ParameterListValueExtractorMethod = - typeof(RelationalSqlTranslatingExpressionVisitor).GetRequiredDeclaredMethod(nameof(ParameterListValueExtractor)); + typeof(RelationalSqlTranslatingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(ParameterListValueExtractor))!; private static readonly MethodInfo StringEqualsWithStringComparison - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Equals), typeof(string), typeof(StringComparison)); + = typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(StringComparison) })!; private static readonly MethodInfo StringEqualsWithStringComparisonStatic - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Equals), typeof(string), typeof(string), typeof(StringComparison)); + = typeof(string).GetRuntimeMethod(nameof(string.Equals), new[] { typeof(string), typeof(string), typeof(StringComparison) })!; private static readonly MethodInfo ObjectEqualsMethodInfo - = typeof(object).GetRequiredRuntimeMethod(nameof(object.Equals), typeof(object), typeof(object)); + = typeof(object).GetRuntimeMethod(nameof(object.Equals), new[] { typeof(object), typeof(object) })!; private readonly QueryCompilationContext _queryCompilationContext; private readonly IModel _model; @@ -1266,7 +1266,7 @@ sqlConstantExpression.Value is null when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal): var lambda = Expression.Lambda( Expression.Call( - ParameterValueExtractorMethid.MakeGenericMethod(property.ClrType.MakeNullable()), + ParameterValueExtractorMethod.MakeGenericMethod(property.ClrType.MakeNullable()), QueryCompilationContext.QueryContextParameter, Expression.Constant(sqlParameterExpression.Name, typeof(string)), Expression.Constant(property, typeof(IProperty))), diff --git a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs index f11cffd8480..8ed9cd1dda9 100644 --- a/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs +++ b/src/EFCore.Relational/Query/SqlExpressions/SelectExpression.cs @@ -1913,8 +1913,8 @@ private Expression AddJoin( AddJoin(joinType, ref innerSelectExpression, out _, joinPredicate); var transparentIdentifierType = TransparentIdentifierFactory.Create(outerShaper.Type, innerShaper.Type); - var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var outerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var innerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var outerClientEval = _clientProjections.Count > 0; var innerClientEval = innerSelectExpression._clientProjections.Count > 0; var innerNullable = joinType == JoinType.LeftJoin || joinType == JoinType.OuterApply; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs index fd4ca1f245d..d42e7c6008a 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerGeometryCollectionMemberTranslator : IMemberTranslator { - private static readonly MemberInfo Count = typeof(GeometryCollection).GetRequiredRuntimeProperty(nameof(GeometryCollection.Count)); + private static readonly MemberInfo Count + = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty(nameof(GeometryCollection.Count))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs index 6ea749b71c7..9f8ec2331c5 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryCollectionMethodTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerGeometryCollectionMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo Item = typeof(GeometryCollection).GetRequiredRuntimeProperty("Item").GetMethod!; + private static readonly MethodInfo Item = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty("Item")!.GetMethod!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs index db2ddf5b81b..508c6a70ba0 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMemberTranslator.cs @@ -16,28 +16,30 @@ public class SqlServerGeometryMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Area)), "STArea" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Dimension)), "STDimension" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.GeometryType)), "STGeometryType" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsEmpty)), "STIsEmpty" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsValid)), "STIsValid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Length)), "STLength" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumGeometries)), "STNumGeometries" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumPoints)), "STNumPoints" } + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Area))!, "STArea" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Dimension))!, "STDimension" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.GeometryType))!, "STGeometryType" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsEmpty))!, "STIsEmpty" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsValid))!, "STIsValid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Length))!, "STLength" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumGeometries))!, "STNumGeometries" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumPoints))!, "STNumPoints" } }; private static readonly IDictionary GeometryMemberToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Boundary)), "STBoundary" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Centroid)), "STCentroid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Envelope)), "STEnvelope" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.InteriorPoint)), "STPointOnSurface" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsSimple)), "STIsSimple" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.PointOnSurface)), "STPointOnSurface" } + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Boundary))!, "STBoundary" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Centroid))!, "STCentroid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Envelope))!, "STEnvelope" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.InteriorPoint))!, "STPointOnSurface" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsSimple))!, "STIsSimple" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.PointOnSurface))!, "STPointOnSurface" } }; - private static readonly MemberInfo OgcGeometryType = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.OgcGeometryType)); - private static readonly MemberInfo Srid = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.SRID)); + private static readonly MemberInfo OgcGeometryType + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.OgcGeometryType))!; + private static readonly MemberInfo Srid + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.SRID))!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs index a4c946a2588..4ddf7d2abf4 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerGeometryMethodTranslator.cs @@ -17,37 +17,37 @@ public class SqlServerGeometryMethodTranslator : IMethodCallTranslator { private static readonly IDictionary MethodToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.AsBinary), Type.EmptyTypes), "STAsBinary" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.AsText), Type.EmptyTypes), "AsTextZM" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Buffer), typeof(double)), "STBuffer" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Contains), typeof(Geometry)), "STContains" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.ConvexHull), Type.EmptyTypes), "STConvexHull" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Difference), typeof(Geometry)), "STDifference" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Disjoint), typeof(Geometry)), "STDisjoint" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Distance), typeof(Geometry)), "STDistance" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.EqualsTopologically), typeof(Geometry)), "STEquals" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Intersection), typeof(Geometry)), "STIntersection" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Intersects), typeof(Geometry)), "STIntersects" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Overlaps), typeof(Geometry)), "STOverlaps" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.SymmetricDifference), typeof(Geometry)), "STSymDifference" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.ToBinary), Type.EmptyTypes), "STAsBinary" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.ToText), Type.EmptyTypes), "AsTextZM" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Union), typeof(Geometry)), "STUnion" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Within), typeof(Geometry)), "STWithin" } + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.AsBinary), Type.EmptyTypes)!, "STAsBinary" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.AsText), Type.EmptyTypes)!, "AsTextZM" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Buffer), new[] { typeof(double) })!, "STBuffer" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Contains), new[] { typeof(Geometry) })!, "STContains" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.ConvexHull), Type.EmptyTypes)!, "STConvexHull" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Difference), new[] { typeof(Geometry) })!, "STDifference" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Disjoint), new[] { typeof(Geometry) })!, "STDisjoint" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Distance), new[] { typeof(Geometry) })!, "STDistance" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.EqualsTopologically), new[] { typeof(Geometry) })!, "STEquals" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Intersection), new[] { typeof(Geometry) })!, "STIntersection" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Intersects), new[] { typeof(Geometry) })!, "STIntersects" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Overlaps), new[] { typeof(Geometry) })!, "STOverlaps" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.SymmetricDifference), new[] { typeof(Geometry) })!, "STSymDifference" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.ToBinary), Type.EmptyTypes)!, "STAsBinary" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.ToText), Type.EmptyTypes)!, "AsTextZM" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Union), new[] { typeof(Geometry) })!, "STUnion" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Within), new[] { typeof(Geometry) })!, "STWithin" } }; private static readonly IDictionary GeometryMethodToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Crosses), typeof(Geometry)), "STCrosses" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Relate), typeof(Geometry), typeof(string)), "STRelate" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Touches), typeof(Geometry)), "STTouches" } + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Crosses), new[] { typeof(Geometry) })!, "STCrosses" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Relate), new[] { typeof(Geometry), typeof(string) })!, "STRelate" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Touches), new[] { typeof(Geometry) })!, "STTouches" } }; - private static readonly MethodInfo GetGeometryN = typeof(Geometry).GetRequiredRuntimeMethod( - nameof(Geometry.GetGeometryN), typeof(int)); + private static readonly MethodInfo GetGeometryN = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.GetGeometryN), new[] { typeof(int) })!; - private static readonly MethodInfo IsWithinDistance = typeof(Geometry).GetRequiredRuntimeMethod( - nameof(Geometry.IsWithinDistance), typeof(Geometry), typeof(double)); + private static readonly MethodInfo IsWithinDistance = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.IsWithinDistance), new[] { typeof(Geometry), typeof(double) })!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs index e3a20c30ec1..8615e1cc6e3 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMemberTranslator.cs @@ -16,11 +16,11 @@ public class SqlServerLineStringMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.Count)), "STNumPoints" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.EndPoint)), "STEndPoint" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsClosed)), "STIsClosed" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.StartPoint)), "STStartPoint" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsRing)), "STIsRing" } + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.Count))!, "STNumPoints" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.EndPoint))!, "STEndPoint" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsClosed))!, "STIsClosed" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.StartPoint))!, "STStartPoint" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsRing))!, "STIsRing" } }; private readonly IRelationalTypeMappingSource _typeMappingSource; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs index 07a835606ec..31598357ac4 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerLineStringMethodTranslator.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerLineStringMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo GetPointN = typeof(LineString).GetRequiredRuntimeMethod( - nameof(LineString.GetPointN), typeof(int)); + private static readonly MethodInfo GetPointN = typeof(LineString).GetRuntimeMethod( + nameof(LineString.GetPointN), new[] { typeof(int) })!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs index 73f580c64a3..59f8598680c 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerMultiLineStringMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerMultiLineStringMemberTranslator : IMemberTranslator { - private static readonly MemberInfo IsClosed = typeof(MultiLineString).GetRequiredRuntimeProperty(nameof(MultiLineString.IsClosed)); + private static readonly MemberInfo IsClosed + = typeof(MultiLineString).GetTypeInfo().GetRuntimeProperty(nameof(MultiLineString.IsClosed))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs index 6a6aa9ade5a..5869ccf2ee1 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPointMemberTranslator.cs @@ -10,20 +10,20 @@ internal class SqlServerPointMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToPropertyName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.M)), "M" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Z)), "Z" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.M))!, "M" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Z))!, "Z" } }; private static readonly IDictionary GeographyMemberToPropertyName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.X)), "Long" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Y)), "Lat" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.X))!, "Long" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Y))!, "Lat" } }; private static readonly IDictionary GeometryMemberToPropertyName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.X)), "STX" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Y)), "STY" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.X))!, "STX" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Y))!, "STY" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs index 09273983c06..1904aba0a7b 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMemberTranslator.cs @@ -14,8 +14,10 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerPolygonMemberTranslator : IMemberTranslator { - private static readonly MemberInfo ExteriorRing = typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.ExteriorRing)); - private static readonly MemberInfo NumInteriorRings = typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.NumInteriorRings)); + private static readonly MemberInfo ExteriorRing + = typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.ExteriorRing))!; + private static readonly MemberInfo NumInteriorRings + = typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.NumInteriorRings))!; private static readonly IDictionary GeometryMemberToFunctionName = new Dictionary { diff --git a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs index eb8c8895db5..f9958c47fd0 100644 --- a/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs +++ b/src/EFCore.SqlServer.NTS/Query/Internal/SqlServerPolygonMethodTranslator.cs @@ -14,8 +14,8 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerPolygonMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo GetInteriorRingN = typeof(Polygon).GetRequiredRuntimeMethod( - nameof(Polygon.GetInteriorRingN), typeof(int)); + private static readonly MethodInfo GetInteriorRingN = typeof(Polygon).GetRuntimeMethod( + nameof(Polygon.GetInteriorRingN), new[] { typeof(int) })!; private readonly IRelationalTypeMappingSource _typeMappingSource; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs b/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs index a76ad47a3b3..1e043cc86c4 100644 --- a/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs +++ b/src/EFCore.SqlServer.NTS/Scaffolding/Internal/SqlServerNetTopologySuiteCodeGeneratorPlugin.cs @@ -12,9 +12,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal; public class SqlServerNetTopologySuiteCodeGeneratorPlugin : ProviderCodeGeneratorPlugin { private static readonly MethodInfo UseNetTopologySuiteMethodInfo - = typeof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod( + = typeof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions).GetRuntimeMethod( nameof(SqlServerNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite), - typeof(SqlServerDbContextOptionsBuilder)); + new[] { typeof(SqlServerDbContextOptionsBuilder) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs index e9795c2aa79..c26efe1b249 100644 --- a/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs +++ b/src/EFCore.SqlServer/Design/Internal/SqlServerAnnotationCodeGenerator.cs @@ -16,88 +16,88 @@ public class SqlServerAnnotationCodeGenerator : AnnotationCodeGenerator #region MethodInfos private static readonly MethodInfo ModelUseIdentityColumnsMethodInfo - = typeof(SqlServerModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerModelBuilderExtensions.UseIdentityColumns), typeof(ModelBuilder), typeof(long), typeof(int)); + = typeof(SqlServerModelBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerModelBuilderExtensions.UseIdentityColumns), new[] { typeof(ModelBuilder), typeof(long), typeof(int) })!; private static readonly MethodInfo ModelUseHiLoMethodInfo - = typeof(SqlServerModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerModelBuilderExtensions.UseHiLo), typeof(ModelBuilder), typeof(string), typeof(string)); + = typeof(SqlServerModelBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerModelBuilderExtensions.UseHiLo), new[] { typeof(ModelBuilder), typeof(string), typeof(string) })!; private static readonly MethodInfo ModelHasDatabaseMaxSizeMethodInfo - = typeof(SqlServerModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerModelBuilderExtensions.HasDatabaseMaxSize), typeof(ModelBuilder), typeof(string)); + = typeof(SqlServerModelBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerModelBuilderExtensions.HasDatabaseMaxSize), new[] { typeof(ModelBuilder), typeof(string) })!; private static readonly MethodInfo ModelHasServiceTierSqlMethodInfo - = typeof(SqlServerModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerModelBuilderExtensions.HasServiceTierSql), typeof(ModelBuilder), typeof(string)); + = typeof(SqlServerModelBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerModelBuilderExtensions.HasServiceTierSql), new[] { typeof(ModelBuilder), typeof(string) })!; private static readonly MethodInfo ModelHasPerformanceLevelSqlMethodInfo - = typeof(SqlServerModelBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerModelBuilderExtensions.HasPerformanceLevelSql), typeof(ModelBuilder), typeof(string)); + = typeof(SqlServerModelBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerModelBuilderExtensions.HasPerformanceLevelSql), new[] { typeof(ModelBuilder), typeof(string) })!; private static readonly MethodInfo ModelHasAnnotationMethodInfo - = typeof(ModelBuilder).GetRequiredRuntimeMethod( - nameof(ModelBuilder.HasAnnotation), typeof(string), typeof(object)); + = typeof(ModelBuilder).GetRuntimeMethod( + nameof(ModelBuilder.HasAnnotation), new[] { typeof(string), typeof(object) })!; private static readonly MethodInfo EntityTypeToTableMethodInfo - = typeof(RelationalEntityTypeBuilderExtensions).GetRequiredRuntimeMethod( - nameof(RelationalEntityTypeBuilderExtensions.ToTable), typeof(EntityTypeBuilder), typeof(string)); + = typeof(RelationalEntityTypeBuilderExtensions).GetRuntimeMethod( + nameof(RelationalEntityTypeBuilderExtensions.ToTable), new[] { typeof(EntityTypeBuilder), typeof(string) })!; private static readonly MethodInfo EntityTypeIsMemoryOptimizedMethodInfo - = typeof(SqlServerEntityTypeBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerEntityTypeBuilderExtensions.IsMemoryOptimized), typeof(EntityTypeBuilder), typeof(bool)); + = typeof(SqlServerEntityTypeBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerEntityTypeBuilderExtensions.IsMemoryOptimized), new[] { typeof(EntityTypeBuilder), typeof(bool) })!; private static readonly MethodInfo PropertyIsSparseMethodInfo - = typeof(SqlServerPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerPropertyBuilderExtensions.IsSparse), typeof(PropertyBuilder), typeof(bool)); + = typeof(SqlServerPropertyBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerPropertyBuilderExtensions.IsSparse), new[] { typeof(PropertyBuilder), typeof(bool) })!; private static readonly MethodInfo PropertyUseIdentityColumnsMethodInfo - = typeof(SqlServerPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerPropertyBuilderExtensions.UseIdentityColumn), typeof(PropertyBuilder), typeof(long), typeof(int)); + = typeof(SqlServerPropertyBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerPropertyBuilderExtensions.UseIdentityColumn), new[] { typeof(PropertyBuilder), typeof(long), typeof(int) })!; private static readonly MethodInfo PropertyUseHiLoMethodInfo - = typeof(SqlServerPropertyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerPropertyBuilderExtensions.UseHiLo), typeof(PropertyBuilder), typeof(string), typeof(string)); + = typeof(SqlServerPropertyBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerPropertyBuilderExtensions.UseHiLo), new[] { typeof(PropertyBuilder), typeof(string), typeof(string) })!; private static readonly MethodInfo IndexIsClusteredMethodInfo - = typeof(SqlServerIndexBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerIndexBuilderExtensions.IsClustered), typeof(IndexBuilder), typeof(bool)); + = typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerIndexBuilderExtensions.IsClustered), new[] { typeof(IndexBuilder), typeof(bool) })!; private static readonly MethodInfo IndexIncludePropertiesMethodInfo - = typeof(SqlServerIndexBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerIndexBuilderExtensions.IncludeProperties), typeof(IndexBuilder), typeof(string[])); + = typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerIndexBuilderExtensions.IncludeProperties), new[] { typeof(IndexBuilder), typeof(string[]) })!; private static readonly MethodInfo IndexHasFillFactorMethodInfo - = typeof(SqlServerIndexBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerIndexBuilderExtensions.HasFillFactor), typeof(IndexBuilder), typeof(int)); + = typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerIndexBuilderExtensions.HasFillFactor), new[] { typeof(IndexBuilder), typeof(int) })!; private static readonly MethodInfo KeyIsClusteredMethodInfo - = typeof(SqlServerKeyBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerKeyBuilderExtensions.IsClustered), typeof(KeyBuilder), typeof(bool)); + = typeof(SqlServerKeyBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerKeyBuilderExtensions.IsClustered), new[] { typeof(KeyBuilder), typeof(bool) })!; private static readonly MethodInfo TableIsTemporalMethodInfo - = typeof(SqlServerTableBuilderExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerTableBuilderExtensions.IsTemporal), typeof(TableBuilder), typeof(bool)); + = typeof(SqlServerTableBuilderExtensions).GetRuntimeMethod( + nameof(SqlServerTableBuilderExtensions.IsTemporal), new[] { typeof(TableBuilder), typeof(bool) })!; private static readonly MethodInfo TemporalTableUseHistoryTableMethodInfo1 - = typeof(TemporalTableBuilder).GetRequiredRuntimeMethod( - nameof(TemporalTableBuilder.UseHistoryTable), typeof(string), typeof(string)); + = typeof(TemporalTableBuilder).GetRuntimeMethod( + nameof(TemporalTableBuilder.UseHistoryTable), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo TemporalTableUseHistoryTableMethodInfo2 - = typeof(TemporalTableBuilder).GetRequiredRuntimeMethod( - nameof(TemporalTableBuilder.UseHistoryTable), typeof(string)); + = typeof(TemporalTableBuilder).GetRuntimeMethod( + nameof(TemporalTableBuilder.UseHistoryTable), new[] { typeof(string) })!; private static readonly MethodInfo TemporalTableHasPeriodStartMethodInfo - = typeof(TemporalTableBuilder).GetRequiredRuntimeMethod( - nameof(TemporalTableBuilder.HasPeriodStart), typeof(string)); + = typeof(TemporalTableBuilder).GetRuntimeMethod( + nameof(TemporalTableBuilder.HasPeriodStart), new[] { typeof(string) })!; private static readonly MethodInfo TemporalTableHasPeriodEndMethodInfo - = typeof(TemporalTableBuilder).GetRequiredRuntimeMethod( - nameof(TemporalTableBuilder.HasPeriodEnd), typeof(string)); + = typeof(TemporalTableBuilder).GetRuntimeMethod( + nameof(TemporalTableBuilder.HasPeriodEnd), new[] { typeof(string) })!; private static readonly MethodInfo TemporalPropertyHasColumnNameMethodInfo - = typeof(TemporalPeriodPropertyBuilder).GetRequiredRuntimeMethod( - nameof(TemporalPeriodPropertyBuilder.HasColumnName), typeof(string)); + = typeof(TemporalPeriodPropertyBuilder).GetRuntimeMethod( + nameof(TemporalPeriodPropertyBuilder.HasColumnName), new[] { typeof(string) })!; #endregion MethodInfos diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs index 7b8ef5654d6..f2483c59a68 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDataLengthFunctionTranslator.cs @@ -23,24 +23,24 @@ public class SqlServerDataLengthFunctionTranslator : IMethodCallTranslator private static readonly HashSet MethodInfoDataLengthMapping = new() { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(string)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(bool?)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(double?)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(decimal?)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(DateTime?)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(TimeSpan?)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(DateTimeOffset?)), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(byte[])), - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DataLength), typeof(DbFunctions), typeof(Guid?)) + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(string) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(bool?) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(double?) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(decimal?) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(DateTime?) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(TimeSpan?) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(DateTimeOffset?) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(byte[]) })!, + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DataLength), new[] { typeof(DbFunctions), typeof(Guid?) })! }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs index 730d18c9a59..708b7205909 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateDiffFunctionsTranslator.cs @@ -18,293 +18,307 @@ private readonly Dictionary _methodInfoDateDiffMapping = new() { { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffYear), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffYear), new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "year" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffYear), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffYear), new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "year" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffYear), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffYear), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "year" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffYear), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffYear), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "year" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "month" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "month" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "month" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMonth), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "month" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffDay), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffDay), new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "day" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffDay), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffDay), new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "day" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffDay), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffDay), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "day" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffDay), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffDay), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "day" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffHour), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffHour), new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "hour" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffHour), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffHour), new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "hour" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffHour), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffHour), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "hour" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffHour), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffHour), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "hour" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffHour), typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffHour), + new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) })!, "hour" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffHour), typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffHour), + new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) })!, "hour" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), + new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "minute" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), + new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "minute" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "minute" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "minute" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), + new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) })!, "minute" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMinute), + new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) })!, "minute" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), + new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "second" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), + new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "second" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "second" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "second" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), + new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) })!, "second" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffSecond), + new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) })!, "second" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), typeof(DbFunctions), typeof(DateTime), - typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), + new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "millisecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), typeof(DbFunctions), typeof(DateTime?), - typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), + new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "millisecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "millisecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "millisecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), typeof(DbFunctions), typeof(TimeSpan), - typeof(TimeSpan)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), + new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) })!, "millisecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), typeof(DbFunctions), typeof(TimeSpan?), - typeof(TimeSpan?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMillisecond), + new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) })!, "millisecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), typeof(DbFunctions), typeof(DateTime), - typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), + new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "microsecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), typeof(DbFunctions), typeof(DateTime?), - typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), + new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "microsecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "microsecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "microsecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), typeof(DbFunctions), typeof(TimeSpan), - typeof(TimeSpan)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), + new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) })!, "microsecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), typeof(DbFunctions), typeof(TimeSpan?), - typeof(TimeSpan?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffMicrosecond), + new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) })!, "microsecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), + new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "nanosecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), typeof(DbFunctions), typeof(DateTime?), - typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), + new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "nanosecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "nanosecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "nanosecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), + new[] { typeof(DbFunctions), typeof(TimeSpan), typeof(TimeSpan) })!, "nanosecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), typeof(DbFunctions), typeof(TimeSpan?), - typeof(TimeSpan?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffNanosecond), + new[] { typeof(DbFunctions), typeof(TimeSpan?), typeof(TimeSpan?) })!, "nanosecond" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), typeof(DbFunctions), typeof(DateTime), typeof(DateTime)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), + new[] { typeof(DbFunctions), typeof(DateTime), typeof(DateTime) })!, "week" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), + new[] { typeof(DbFunctions), typeof(DateTime?), typeof(DateTime?) })!, "week" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), typeof(DbFunctions), typeof(DateTimeOffset), - typeof(DateTimeOffset)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), + new[] { typeof(DbFunctions), typeof(DateTimeOffset), typeof(DateTimeOffset) })!, "week" }, { - typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), typeof(DbFunctions), typeof(DateTimeOffset?), - typeof(DateTimeOffset?)), + typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateDiffWeek), + new[] { typeof(DbFunctions), typeof(DateTimeOffset?), typeof(DateTimeOffset?) })!, "week" } }; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs index 8c9e008373c..f5469dbb8cf 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMethodTranslator.cs @@ -15,20 +15,20 @@ public class SqlServerDateTimeMethodTranslator : IMethodCallTranslator { private readonly Dictionary _methodInfoDatePartMapping = new() { - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddYears), typeof(int)), "year" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddMonths), typeof(int)), "month" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddDays), typeof(double)), "day" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddHours), typeof(double)), "hour" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddMinutes), typeof(double)), "minute" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddSeconds), typeof(double)), "second" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddMilliseconds), typeof(double)), "millisecond" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddYears), typeof(int)), "year" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddMonths), typeof(int)), "month" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddDays), typeof(double)), "day" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddHours), typeof(double)), "hour" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddMinutes), typeof(double)), "minute" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddSeconds), typeof(double)), "second" }, - { typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.AddMilliseconds), typeof(double)), "millisecond" } + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddYears), new[] { typeof(int) })!, "year" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMonths), new[] { typeof(int) })!, "month" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddDays), new[] { typeof(double) })!, "day" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddHours), new[] { typeof(double) })!, "hour" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMinutes), new[] { typeof(double) })!, "minute" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddSeconds), new[] { typeof(double) })!, "second" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMilliseconds), new[] { typeof(double) })!, "millisecond" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddYears), new[] { typeof(int) })!, "year" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddMonths), new[] { typeof(int) })!, "month" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddDays), new[] { typeof(double) })!, "day" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddHours), new[] { typeof(double) })!, "hour" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddMinutes), new[] { typeof(double) })!, "minute" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddSeconds), new[] { typeof(double) })!, "second" }, + { typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.AddMilliseconds), new[] { typeof(double) })!, "millisecond" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs index 1934357c3df..2172d0ba2f8 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerFromPartsFunctionTranslator.cs @@ -14,33 +14,58 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; public class SqlServerFromPartsFunctionTranslator : IMethodCallTranslator { private static readonly MethodInfo DateFromPartsMethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateFromParts), typeof(DbFunctions), typeof(int), typeof(int), typeof(int)); + .GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateFromParts), + new[] {typeof(DbFunctions), typeof(int), typeof(int), typeof(int) })!; private static readonly MethodInfo DateTimeFromPartsMethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateTimeFromParts), typeof(DbFunctions), typeof(int), typeof(int), typeof(int), - typeof(int), typeof(int), typeof(int), typeof(int)); + .GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateTimeFromParts), + new[] { typeof(DbFunctions), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) })!; private static readonly MethodInfo DateTime2FromPartsMethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateTime2FromParts), typeof(DbFunctions), typeof(int), typeof(int), typeof(int), - typeof(int), typeof(int), typeof(int), typeof(int), typeof(int)); + .GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateTime2FromParts), + new[] + { + typeof(DbFunctions), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int) + })!; private static readonly MethodInfo DateTimeOffsetFromPartsMethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.DateTimeOffsetFromParts), typeof(DbFunctions), typeof(int), typeof(int), typeof(int), - typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int)); + .GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.DateTimeOffsetFromParts), + new[] + { + typeof(DbFunctions), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int), + typeof(int) + })!; private static readonly MethodInfo SmallDateTimeFromPartsMethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.SmallDateTimeFromParts), typeof(DbFunctions), typeof(int), typeof(int), typeof(int), - typeof(int), typeof(int)); + .GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.SmallDateTimeFromParts), + new[] { typeof(DbFunctions), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) })!; private static readonly MethodInfo TimeFromPartsMethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.TimeFromParts), typeof(DbFunctions), typeof(int), typeof(int), typeof(int), - typeof(int), typeof(int)); + .GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.TimeFromParts), + new[] { typeof(DbFunctions), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) })!; private static readonly IDictionary MethodFunctionMapping = new Dictionary diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs index a2046b5212f..5854b7ab1af 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerFullTextSearchFunctionsTranslator.cs @@ -18,20 +18,22 @@ public class SqlServerFullTextSearchFunctionsTranslator : IMethodCallTranslator private const string ContainsFunctionName = "CONTAINS"; private static readonly MethodInfo FreeTextMethodInfo - = typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.FreeText), typeof(DbFunctions), typeof(object), typeof(string)); + = typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.FreeText), new[] { typeof(DbFunctions), typeof(object), typeof(string) })!; private static readonly MethodInfo FreeTextMethodInfoWithLanguage - = typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.FreeText), typeof(DbFunctions), typeof(object), typeof(string), typeof(int)); + = typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.FreeText), + new[] { typeof(DbFunctions), typeof(object), typeof(string), typeof(int) })!; private static readonly MethodInfo ContainsMethodInfo - = typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.Contains), typeof(DbFunctions), typeof(object), typeof(string)); + = typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.Contains), new[] { typeof(DbFunctions), typeof(object), typeof(string) })!; private static readonly MethodInfo ContainsMethodInfoWithLanguage - = typeof(SqlServerDbFunctionsExtensions).GetRequiredRuntimeMethod( - nameof(SqlServerDbFunctionsExtensions.Contains), typeof(DbFunctions), typeof(object), typeof(string), typeof(int)); + = typeof(SqlServerDbFunctionsExtensions).GetRuntimeMethod( + nameof(SqlServerDbFunctionsExtensions.Contains), + new[] { typeof(DbFunctions), typeof(object), typeof(string), typeof(int) })!; private static readonly IDictionary FunctionMapping = new Dictionary diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs index 2598fc37143..8765264cae6 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerIsDateFunctionTranslator.cs @@ -16,7 +16,7 @@ public class SqlServerIsDateFunctionTranslator : IMethodCallTranslator private readonly ISqlExpressionFactory _sqlExpressionFactory; private static readonly MethodInfo MethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod(nameof(SqlServerDbFunctionsExtensions.IsDate), typeof(DbFunctions), typeof(string)); + .GetRuntimeMethod(nameof(SqlServerDbFunctionsExtensions.IsDate), new[] { typeof(DbFunctions), typeof(string) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerIsNumericFunctionTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerIsNumericFunctionTranslator.cs index aab6d54cec0..aa8c2feaf91 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerIsNumericFunctionTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerIsNumericFunctionTranslator.cs @@ -16,7 +16,7 @@ public class SqlServerIsNumericFunctionTranslator : IMethodCallTranslator private readonly ISqlExpressionFactory _sqlExpressionFactory; private static readonly MethodInfo MethodInfo = typeof(SqlServerDbFunctionsExtensions) - .GetRequiredRuntimeMethod(nameof(SqlServerDbFunctionsExtensions.IsNumeric), typeof(DbFunctions), typeof(string)); + .GetRuntimeMethod(nameof(SqlServerDbFunctionsExtensions.IsNumeric), new[] { typeof(DbFunctions), typeof(string) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs index bd94cb2898c..6a4012e6772 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerMathTranslator.cs @@ -16,71 +16,71 @@ public class SqlServerMathTranslator : IMethodCallTranslator { private static readonly Dictionary SupportedMethodTranslations = new() { - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(decimal)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(double)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(float)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(int)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(long)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(sbyte)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Abs), typeof(short)), "ABS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Ceiling), typeof(decimal)), "CEILING" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Ceiling), typeof(double)), "CEILING" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Floor), typeof(decimal)), "FLOOR" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Floor), typeof(double)), "FLOOR" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Pow), typeof(double), typeof(double)), "POWER" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Exp), typeof(double)), "EXP" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Log10), typeof(double)), "LOG10" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Log), typeof(double)), "LOG" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Log), typeof(double), typeof(double)), "LOG" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sqrt), typeof(double)), "SQRT" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Acos), typeof(double)), "ACOS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Asin), typeof(double)), "ASIN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Atan), typeof(double)), "ATAN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Atan2), typeof(double), typeof(double)), "ATN2" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Cos), typeof(double)), "COS" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sin), typeof(double)), "SIN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Tan), typeof(double)), "TAN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(decimal)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(double)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(float)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(int)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(long)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(sbyte)), "SIGN" }, - { typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Sign), typeof(short)), "SIGN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Abs), typeof(float)), "ABS" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Ceiling), typeof(float)), "CEILING" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Floor), typeof(float)), "FLOOR" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Pow), typeof(float), typeof(float)), "POWER" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Exp), typeof(float)), "EXP" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Log10), typeof(float)), "LOG10" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Log), typeof(float)), "LOG" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Log), typeof(float), typeof(float)), "LOG" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Sqrt), typeof(float)), "SQRT" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Acos), typeof(float)), "ACOS" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Asin), typeof(float)), "ASIN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Atan), typeof(float)), "ATAN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Atan2), typeof(float), typeof(float)), "ATN2" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Cos), typeof(float)), "COS" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Sin), typeof(float)), "SIN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Tan), typeof(float)), "TAN" }, - { typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Sign), typeof(float)), "SIGN" } + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(decimal) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(double) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(float) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(int) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(long) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(sbyte) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Abs), new[] { typeof(short) })!, "ABS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Ceiling), new[] { typeof(decimal) })!, "CEILING" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Ceiling), new[] { typeof(double) })!, "CEILING" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Floor), new[] { typeof(decimal) })!, "FLOOR" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Floor), new[] { typeof(double) })!, "FLOOR" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Pow), new[] { typeof(double), typeof(double) })!, "POWER" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Exp), new[] { typeof(double) })!, "EXP" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Log10), new[] { typeof(double) })!, "LOG10" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double) })!, "LOG" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Log), new[] { typeof(double), typeof(double) })!, "LOG" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sqrt), new[] { typeof(double) })!, "SQRT" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Acos), new[] { typeof(double) })!, "ACOS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Asin), new[] { typeof(double) })!, "ASIN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Atan), new[] { typeof(double) })!, "ATAN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Atan2), new[] { typeof(double), typeof(double) })!, "ATN2" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Cos), new[] { typeof(double) })!, "COS" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sin), new[] { typeof(double) })!, "SIN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Tan), new[] { typeof(double) })!, "TAN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(decimal) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(double) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(float) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(int) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(long) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(sbyte) })!, "SIGN" }, + { typeof(Math).GetRuntimeMethod(nameof(Math.Sign), new[] { typeof(short) })!, "SIGN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "ABS" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Ceiling), new[] { typeof(float) })!, "CEILING" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Floor), new[] { typeof(float) })!, "FLOOR" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Pow), new[] { typeof(float), typeof(float) })!, "POWER" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Exp), new[] { typeof(float) })!, "EXP" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Log10), new[] { typeof(float) })!, "LOG10" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Log), new[] { typeof(float) })!, "LOG" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Log), new[] { typeof(float), typeof(float) })!, "LOG" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Sqrt), new[] { typeof(float) })!, "SQRT" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Acos), new[] { typeof(float) })!, "ACOS" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Asin), new[] { typeof(float) })!, "ASIN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Atan), new[] { typeof(float) })!, "ATAN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Atan2), new[] { typeof(float), typeof(float) })!, "ATN2" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Cos), new[] { typeof(float) })!, "COS" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Sin), new[] { typeof(float) })!, "SIN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Tan), new[] { typeof(float) })!, "TAN" }, + { typeof(MathF).GetRuntimeMethod(nameof(MathF.Sign), new[] { typeof(float) })!, "SIGN" } }; private static readonly IEnumerable TruncateMethodInfos = new[] { - typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Truncate), typeof(decimal)), - typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Truncate), typeof(double)), - typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Truncate), typeof(float)) + typeof(Math).GetRuntimeMethod(nameof(Math.Truncate), new[] { typeof(decimal) })!, + typeof(Math).GetRuntimeMethod(nameof(Math.Truncate), new[] { typeof(double) })!, + typeof(MathF).GetRuntimeMethod(nameof(MathF.Truncate), new[] { typeof(float) })! }; private static readonly IEnumerable RoundMethodInfos = new[] { - typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), typeof(decimal)), - typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), typeof(double)), - typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), typeof(decimal), typeof(int)), - typeof(Math).GetRequiredRuntimeMethod(nameof(Math.Round), typeof(double), typeof(int)), - typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Round), typeof(float)), - typeof(MathF).GetRequiredRuntimeMethod(nameof(MathF.Round), typeof(float), typeof(int)) + typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(decimal) })!, + typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(double) })!, + typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(decimal), typeof(int) })!, + typeof(Math).GetRuntimeMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) })!, + typeof(MathF).GetRuntimeMethod(nameof(MathF.Round), new[] { typeof(float) })!, + typeof(MathF).GetRuntimeMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })! }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs index 7d19ddc40e8..87036517db0 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerNewGuidTranslator.cs @@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; /// public class SqlServerNewGuidTranslator : IMethodCallTranslator { - private static readonly MethodInfo MethodInfo = typeof(Guid).GetRequiredRuntimeMethod(nameof(Guid.NewGuid), Array.Empty()); + private static readonly MethodInfo MethodInfo = typeof(Guid).GetRuntimeMethod(nameof(Guid.NewGuid), Type.EmptyTypes)!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs index 02af91d2f1f..9d51409f1f0 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerStringMethodTranslator.cs @@ -16,60 +16,60 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Query.Internal; public class SqlServerStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo IndexOfMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string) })!; private static readonly MethodInfo IndexOfMethodInfoWithStartingPosition - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string), typeof(int) })!; private static readonly MethodInfo ReplaceMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Replace), typeof(string), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Replace), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo ToLowerMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.ToLower), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.ToLower), Type.EmptyTypes)!; private static readonly MethodInfo ToUpperMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.ToUpper), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.ToUpper), Type.EmptyTypes)!; private static readonly MethodInfo SubstringMethodInfoWithOneArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int) })!; private static readonly MethodInfo SubstringMethodInfoWithTwoArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int), typeof(int) })!; private static readonly MethodInfo IsNullOrEmptyMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IsNullOrEmpty), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IsNullOrEmpty), new[] { typeof(string) })!; private static readonly MethodInfo IsNullOrWhiteSpaceMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IsNullOrWhiteSpace), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IsNullOrWhiteSpace), new[] { typeof(string) })!; // Method defined in netcoreapp2.0 only private static readonly MethodInfo TrimStartMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), Type.EmptyTypes)!; private static readonly MethodInfo TrimEndMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), Type.EmptyTypes)!; private static readonly MethodInfo TrimMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), Type.EmptyTypes)!; // Method defined in netstandard2.0 private static readonly MethodInfo TrimStartMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char[]) })!; private static readonly MethodInfo TrimEndMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char[]) })!; private static readonly MethodInfo TrimMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char[]) })!; private static readonly MethodInfo StartsWithMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.StartsWith), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) })!; private static readonly MethodInfo ContainsMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Contains), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) })!; private static readonly MethodInfo EndsWithMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.EndsWith), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) })!; private static readonly MethodInfo FirstOrDefaultMethodInfoWithoutArgs = typeof(Enumerable).GetRuntimeMethods().Single( diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs index cb60c050545..2dbc8fa8946 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerCodeGenerator.cs @@ -12,11 +12,9 @@ namespace Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal; public class SqlServerCodeGenerator : ProviderCodeGenerator { private static readonly MethodInfo UseSqlServerMethodInfo - = typeof(SqlServerDbContextOptionsExtensions).GetRequiredRuntimeMethod( + = typeof(SqlServerDbContextOptionsExtensions).GetRuntimeMethod( nameof(SqlServerDbContextOptionsExtensions.UseSqlServer), - typeof(DbContextOptionsBuilder), - typeof(string), - typeof(Action)); + new[] { typeof(DbContextOptionsBuilder), typeof(string), typeof(Action) })!; /// /// Initializes a new instance of the class. diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteCharMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteCharMethodTranslator.cs index b5a576ab91f..34a519b4338 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteCharMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteCharMethodTranslator.cs @@ -15,8 +15,8 @@ public class SqliteCharMethodTranslator : IMethodCallTranslator { private static readonly Dictionary SupportedMethods = new() { - { typeof(char).GetRequiredRuntimeMethod(nameof(char.ToLower), typeof(char)), "lower" }, - { typeof(char).GetRequiredRuntimeMethod(nameof(char.ToUpper), typeof(char)), "upper" } + { typeof(char).GetRuntimeMethod(nameof(char.ToLower), new[] { typeof(char) })!, "lower" }, + { typeof(char).GetRuntimeMethod(nameof(char.ToUpper), new[] { typeof(char) })!, "upper" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs index a8f474bbaf5..019b73d10e1 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs @@ -14,22 +14,22 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteDateTimeAddTranslator : IMethodCallTranslator { private static readonly MethodInfo AddMilliseconds - = typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddMilliseconds), typeof(double)); + = typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMilliseconds), new[] { typeof(double) })!; private static readonly MethodInfo AddTicks - = typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddTicks), typeof(long)); + = typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddTicks), new[] { typeof(long) })!; private readonly Dictionary _methodInfoToUnitSuffix = new() { - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddYears), typeof(int)), " years" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddMonths), typeof(int)), " months" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddDays), typeof(double)), " days" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddHours), typeof(double)), " hours" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddMinutes), typeof(double)), " minutes" }, - { typeof(DateTime).GetRequiredRuntimeMethod(nameof(DateTime.AddSeconds), typeof(double)), " seconds" }, - { typeof(DateOnly).GetRequiredRuntimeMethod(nameof(DateOnly.AddYears), typeof(int)), " years" }, - { typeof(DateOnly).GetRequiredRuntimeMethod(nameof(DateOnly.AddMonths), typeof(int)), " months" }, - { typeof(DateOnly).GetRequiredRuntimeMethod(nameof(DateOnly.AddDays), typeof(int)), " days" } + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddYears), new[] { typeof(int) })!, " years" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMonths), new[] { typeof(int) })!, " months" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddDays), new[] { typeof(double) })!, " days" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddHours), new[] { typeof(double) })!, " hours" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddMinutes), new[] { typeof(double) })!, " minutes" }, + { typeof(DateTime).GetRuntimeMethod(nameof(DateTime.AddSeconds), new[] { typeof(double) })!, " seconds" }, + { typeof(DateOnly).GetRuntimeMethod(nameof(DateOnly.AddYears), new[] { typeof(int) })!, " years" }, + { typeof(DateOnly).GetRuntimeMethod(nameof(DateOnly.AddMonths), new[] { typeof(int) })!, " months" }, + { typeof(DateOnly).GetRuntimeMethod(nameof(DateOnly.AddDays), new[] { typeof(int) })!, " days" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs index 61e7e52ac07..2de04affc5c 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteGlobMethodTranslator.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteGlobMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod(nameof(SqliteDbFunctionsExtensions.Glob), typeof(DbFunctions), typeof(string), typeof(string)); + .GetMethod(nameof(SqliteDbFunctionsExtensions.Glob), new[] { typeof(DbFunctions), typeof(string), typeof(string) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs index 41b7b57d0d8..68e759f7a85 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteHexMethodTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteHexMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod(nameof(SqliteDbFunctionsExtensions.Hex), typeof(DbFunctions), typeof(byte[])); + .GetMethod(nameof(SqliteDbFunctionsExtensions.Hex), new[] { typeof(DbFunctions), typeof(byte[]) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs index 51e36965cd8..60c3f13e46e 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteMathTranslator.cs @@ -16,37 +16,37 @@ public class SqliteMathTranslator : IMethodCallTranslator { private static readonly Dictionary SupportedMethods = new() { - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(double)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(float)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(int)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(long)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(sbyte)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Abs), typeof(short)), "abs" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(byte), typeof(byte)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(double), typeof(double)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(float), typeof(float)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(int), typeof(int)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(long), typeof(long)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(sbyte), typeof(sbyte)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(short), typeof(short)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(uint), typeof(uint)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Max), typeof(ushort), typeof(ushort)), "max" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(byte), typeof(byte)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(double), typeof(double)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(float), typeof(float)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(int), typeof(int)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(long), typeof(long)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(sbyte), typeof(sbyte)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(short), typeof(short)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(uint), typeof(uint)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Min), typeof(ushort), typeof(ushort)), "min" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Round), typeof(double)), "round" }, - { typeof(Math).GetRequiredMethod(nameof(Math.Round), typeof(double), typeof(int)), "round" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Abs), typeof(float)), "abs" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Max), typeof(float), typeof(float)), "max" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Min), typeof(float), typeof(float)), "min" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Round), typeof(float)), "round" }, - { typeof(MathF).GetRequiredMethod(nameof(MathF.Round), typeof(float), typeof(int)), "round" } + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(double) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(float) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(int) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(long) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(sbyte) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(short) })!, "abs" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(byte), typeof(byte) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(float), typeof(float) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(int), typeof(int) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(long), typeof(long) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(sbyte), typeof(sbyte) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(short), typeof(short) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(uint), typeof(uint) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(ushort), typeof(ushort) })!, "max" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(byte), typeof(byte) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(double), typeof(double) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(float), typeof(float) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(int), typeof(int) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(long), typeof(long) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(sbyte), typeof(sbyte) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(short), typeof(short) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(uint), typeof(uint) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(ushort), typeof(ushort) })!, "min" }, + { typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double) })!, "round" }, + { typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) })!, "round" }, + { typeof(MathF).GetMethod(nameof(MathF.Abs), new[] { typeof(float) })!, "abs" }, + { typeof(MathF).GetMethod(nameof(MathF.Max), new[] { typeof(float), typeof(float) })!, "max" }, + { typeof(MathF).GetMethod(nameof(MathF.Min), new[] { typeof(float), typeof(float) })!, "min" }, + { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float) })!, "round" }, + { typeof(MathF).GetMethod(nameof(MathF.Round), new[] { typeof(float), typeof(int) })!, "round" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs index 8fcc84dfffb..0670c539e9b 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteRandomTranslator.cs @@ -13,8 +13,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteRandomTranslator : IMethodCallTranslator { - private static readonly MethodInfo MethodInfo = typeof(DbFunctionsExtensions).GetRequiredMethod( - nameof(DbFunctionsExtensions.Random), typeof(DbFunctions)); + private static readonly MethodInfo MethodInfo + = typeof(DbFunctionsExtensions).GetMethod(nameof(DbFunctionsExtensions.Random), new[] { typeof(DbFunctions) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteRegexMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteRegexMethodTranslator.cs index b545a16fb92..5e1cccd098b 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteRegexMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteRegexMethodTranslator.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteRegexMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo RegexIsMatchMethodInfo - = typeof(Regex).GetRequiredRuntimeMethod(nameof(Regex.IsMatch), typeof(string), typeof(string)); + = typeof(Regex).GetRuntimeMethod(nameof(Regex.IsMatch), new[] { typeof(string), typeof(string) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs index fa04463b7cc..2e3302dfe29 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteStringMethodTranslator.cs @@ -16,63 +16,63 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo IndexOfMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IndexOf), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IndexOf), new[] { typeof(string) })!; private static readonly MethodInfo ReplaceMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Replace), typeof(string), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Replace), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo ToLowerMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.ToLower), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.ToLower), Type.EmptyTypes)!; private static readonly MethodInfo ToUpperMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.ToUpper), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.ToUpper), Type.EmptyTypes)!; private static readonly MethodInfo SubstringMethodInfoWithOneArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int) })!; private static readonly MethodInfo SubstringMethodInfoWithTwoArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Substring), typeof(int), typeof(int)); + = typeof(string).GetRuntimeMethod(nameof(string.Substring), new[] { typeof(int), typeof(int) })!; private static readonly MethodInfo IsNullOrWhiteSpaceMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.IsNullOrWhiteSpace), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.IsNullOrWhiteSpace), new[] { typeof(string) })!; // Method defined in netcoreapp2.0 only private static readonly MethodInfo TrimStartMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), Type.EmptyTypes)!; private static readonly MethodInfo TrimStartMethodInfoWithCharArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), typeof(char)); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char) })!; private static readonly MethodInfo TrimEndMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), Type.EmptyTypes)!; private static readonly MethodInfo TrimEndMethodInfoWithCharArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), typeof(char)); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char) })!; private static readonly MethodInfo TrimMethodInfoWithoutArgs - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), Array.Empty()); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), Type.EmptyTypes)!; private static readonly MethodInfo TrimMethodInfoWithCharArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), typeof(char)); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char) })!; // Method defined in netstandard2.0 private static readonly MethodInfo TrimStartMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimStart), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.TrimStart), new[] { typeof(char[]) })!; private static readonly MethodInfo TrimEndMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.TrimEnd), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.TrimEnd), new[] { typeof(char[]) })!; private static readonly MethodInfo TrimMethodInfoWithCharArrayArg - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Trim), typeof(char[])); + = typeof(string).GetRuntimeMethod(nameof(string.Trim), new[] { typeof(char[]) })!; private static readonly MethodInfo StartsWithMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.StartsWith), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) })!; private static readonly MethodInfo ContainsMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.Contains), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.Contains), new[] { typeof(string) })!; private static readonly MethodInfo EndsWithMethodInfo - = typeof(string).GetRequiredRuntimeMethod(nameof(string.EndsWith), typeof(string)); + = typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) })!; private static readonly MethodInfo FirstOrDefaultMethodInfoWithoutArgs = typeof(Enumerable).GetRuntimeMethods().Single( diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs index e27b07e3d21..a6455f484d4 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteSubstrMethodTranslator.cs @@ -14,11 +14,11 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteSubstrMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo MethodInfo = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod(nameof(SqliteDbFunctionsExtensions.Substr), typeof(DbFunctions), typeof(byte[]), typeof(int)); + .GetMethod(nameof(SqliteDbFunctionsExtensions.Substr), new[] { typeof(DbFunctions), typeof(byte[]), typeof(int) })!; private static readonly MethodInfo MethodInfoWithLength = typeof(SqliteDbFunctionsExtensions) - .GetRequiredMethod( - nameof(SqliteDbFunctionsExtensions.Substr), typeof(DbFunctions), typeof(byte[]), typeof(int), typeof(int)); + .GetMethod( + nameof(SqliteDbFunctionsExtensions.Substr), new[] { typeof(DbFunctions), typeof(byte[]), typeof(int), typeof(int) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs index 132c7ffed78..0110c340d44 100644 --- a/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs +++ b/src/EFCore.Sqlite.Core/Scaffolding/Internal/SqliteCodeGenerator.cs @@ -12,11 +12,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal; public class SqliteCodeGenerator : ProviderCodeGenerator { private static readonly MethodInfo UseSqliteMethodInfo - = typeof(SqliteDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod( + = typeof(SqliteDbContextOptionsBuilderExtensions).GetRuntimeMethod( nameof(SqliteDbContextOptionsBuilderExtensions.UseSqlite), - typeof(DbContextOptionsBuilder), - typeof(string), - typeof(Action)); + new[] { typeof(DbContextOptionsBuilder), typeof(string), typeof(Action) })!; /// /// Initializes a new instance of the class. diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs index 6694b6fd799..b6f7fba1ff1 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteGeometryCollectionMemberTranslator : IMemberTranslator { - private static readonly MemberInfo Count = typeof(GeometryCollection).GetRequiredRuntimeProperty(nameof(GeometryCollection.Count)); + private static readonly MemberInfo Count + = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty(nameof(GeometryCollection.Count))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs index ebe9e83a546..ed0fb221f45 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryCollectionMethodTranslator.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteGeometryCollectionMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo Item = typeof(GeometryCollection).GetRequiredRuntimeProperty("Item").GetMethod!; + private static readonly MethodInfo Item = typeof(GeometryCollection).GetTypeInfo().GetRuntimeProperty("Item")!.GetMethod!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs index 15245ab15d2..acb882a21bf 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMemberTranslator.cs @@ -16,24 +16,26 @@ public class SqliteGeometryMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Area)), "Area" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Boundary)), "Boundary" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Centroid)), "Centroid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Dimension)), "Dimension" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Envelope)), "Envelope" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.InteriorPoint)), "PointOnSurface" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsEmpty)), "IsEmpty" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsSimple)), "IsSimple" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.IsValid)), "IsValid" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.Length)), "GLength" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumGeometries)), "NumGeometries" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.NumPoints)), "NumPoints" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.PointOnSurface)), "PointOnSurface" }, - { typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.SRID)), "SRID" } + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Area))!, "Area" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Boundary))!, "Boundary" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Centroid))!, "Centroid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Dimension))!, "Dimension" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Envelope))!, "Envelope" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.InteriorPoint))!, "PointOnSurface" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsEmpty))!, "IsEmpty" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsSimple))!, "IsSimple" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.IsValid))!, "IsValid" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.Length))!, "GLength" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumGeometries))!, "NumGeometries" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.NumPoints))!, "NumPoints" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.PointOnSurface))!, "PointOnSurface" }, + { typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.SRID))!, "SRID" } }; - private static readonly MemberInfo GeometryType = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.GeometryType)); - private static readonly MemberInfo OgcGeometryType = typeof(Geometry).GetRequiredRuntimeProperty(nameof(Geometry.OgcGeometryType)); + private static readonly MemberInfo GeometryType + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.GeometryType))!; + private static readonly MemberInfo OgcGeometryType + = typeof(Geometry).GetTypeInfo().GetRuntimeProperty(nameof(Geometry.OgcGeometryType))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs index a208f1768e5..379992cf21e 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteGeometryMethodTranslator.cs @@ -16,38 +16,38 @@ public class SqliteGeometryMethodTranslator : IMethodCallTranslator { private static readonly IDictionary MethodToFunctionName = new Dictionary { - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.AsBinary), Type.EmptyTypes), "AsBinary" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.AsText), Type.EmptyTypes), "AsText" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Buffer), typeof(double)), "Buffer" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Buffer), typeof(double), typeof(int)), "Buffer" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Contains), typeof(Geometry)), "Contains" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.ConvexHull), Type.EmptyTypes), "ConvexHull" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Crosses), typeof(Geometry)), "Crosses" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.CoveredBy), typeof(Geometry)), "CoveredBy" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Covers), typeof(Geometry)), "Covers" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Difference), typeof(Geometry)), "Difference" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Disjoint), typeof(Geometry)), "Disjoint" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Distance), typeof(Geometry)), "Distance" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.EqualsTopologically), typeof(Geometry)), "Equals" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Intersection), typeof(Geometry)), "Intersection" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Intersects), typeof(Geometry)), "Intersects" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Overlaps), typeof(Geometry)), "Overlaps" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Relate), typeof(Geometry), typeof(string)), "Relate" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Reverse), Type.EmptyTypes), "ST_Reverse" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.SymmetricDifference), typeof(Geometry)), "SymDifference" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.ToBinary), Type.EmptyTypes), "AsBinary" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.ToText), Type.EmptyTypes), "AsText" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Touches), typeof(Geometry)), "Touches" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Union), Type.EmptyTypes), "UnaryUnion" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Union), typeof(Geometry)), "GUnion" }, - { typeof(Geometry).GetRequiredRuntimeMethod(nameof(Geometry.Within), typeof(Geometry)), "Within" } + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.AsBinary), Type.EmptyTypes)!, "AsBinary" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.AsText), Type.EmptyTypes)!, "AsText" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Buffer), new[] { typeof(double) })!, "Buffer" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Buffer), new[] { typeof(double), typeof(int) })!, "Buffer" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Contains), new[] { typeof(Geometry) })!, "Contains" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.ConvexHull), Type.EmptyTypes)!, "ConvexHull" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Crosses), new[] { typeof(Geometry) })!, "Crosses" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.CoveredBy), new[] { typeof(Geometry) })!, "CoveredBy" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Covers), new[] { typeof(Geometry) })!, "Covers" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Difference), new[] { typeof(Geometry) })!, "Difference" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Disjoint), new[] { typeof(Geometry) })!, "Disjoint" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Distance), new[] { typeof(Geometry) })!, "Distance" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.EqualsTopologically), new[] { typeof(Geometry) })!, "Equals" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Intersection), new[] { typeof(Geometry) })!, "Intersection" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Intersects), new[] { typeof(Geometry) })!, "Intersects" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Overlaps), new[] { typeof(Geometry) })!, "Overlaps" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Relate), new[] { typeof(Geometry), typeof(string) })!, "Relate" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Reverse), Type.EmptyTypes)!, "ST_Reverse" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.SymmetricDifference), new[] { typeof(Geometry) })!, "SymDifference" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.ToBinary), Type.EmptyTypes)!, "AsBinary" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.ToText), Type.EmptyTypes)!, "AsText" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Touches), new[] { typeof(Geometry) })!, "Touches" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Union), Type.EmptyTypes)!, "UnaryUnion" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Union), new[] { typeof(Geometry) })!, "GUnion" }, + { typeof(Geometry).GetRuntimeMethod(nameof(Geometry.Within), new[] { typeof(Geometry) })!, "Within" } }; - private static readonly MethodInfo GetGeometryN = typeof(Geometry).GetRequiredRuntimeMethod( - nameof(Geometry.GetGeometryN), typeof(int)); + private static readonly MethodInfo GetGeometryN = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.GetGeometryN), new[] { typeof(int) })!; - private static readonly MethodInfo IsWithinDistance = typeof(Geometry).GetRequiredRuntimeMethod( - nameof(Geometry.IsWithinDistance), typeof(Geometry), typeof(double)); + private static readonly MethodInfo IsWithinDistance = typeof(Geometry).GetRuntimeMethod( + nameof(Geometry.IsWithinDistance), new[] { typeof(Geometry), typeof(double) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs index 1bc0794284a..0dfa4f6527e 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMemberTranslator.cs @@ -17,11 +17,11 @@ public class SqliteLineStringMemberTranslator : IMemberTranslator private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.Count)), "NumPoints" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.EndPoint)), "EndPoint" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsClosed)), "IsClosed" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.IsRing)), "IsRing" }, - { typeof(LineString).GetRequiredRuntimeProperty(nameof(LineString.StartPoint)), "StartPoint" } + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.Count))!, "NumPoints" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.EndPoint))!, "EndPoint" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsClosed))!, "IsClosed" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.IsRing))!, "IsRing" }, + { typeof(LineString).GetTypeInfo().GetRuntimeProperty(nameof(LineString.StartPoint))!, "StartPoint" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs index 2e22e3ec28e..44f784d64aa 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteLineStringMethodTranslator.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqliteLineStringMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo GetPointN - = typeof(LineString).GetRequiredRuntimeMethod(nameof(LineString.GetPointN), typeof(int)); + = typeof(LineString).GetRuntimeMethod(nameof(LineString.GetPointN), new[] { typeof(int) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs index e5f77718281..3aff3787272 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqliteMultiLineStringMemberTranslator.cs @@ -14,7 +14,8 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; /// public class SqliteMultiLineStringMemberTranslator : IMemberTranslator { - private static readonly MemberInfo IsClosed = typeof(MultiLineString).GetRequiredRuntimeProperty(nameof(MultiLineString.IsClosed)); + private static readonly MemberInfo IsClosed + = typeof(MultiLineString).GetTypeInfo().GetRuntimeProperty(nameof(MultiLineString.IsClosed))!; private readonly ISqlExpressionFactory _sqlExpressionFactory; /// diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs index f3fa7426055..989c0f8a642 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePointMemberTranslator.cs @@ -16,10 +16,10 @@ public class SqlitePointMemberTranslator : IMemberTranslator { private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.M)), "M" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.X)), "X" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Y)), "Y" }, - { typeof(Point).GetRequiredRuntimeProperty(nameof(Point.Z)), "Z" } + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.M))!, "M" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.X))!, "X" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Y))!, "Y" }, + { typeof(Point).GetTypeInfo().GetRuntimeProperty(nameof(Point.Z))!, "Z" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs index 00c14af90b9..b49727df557 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMemberTranslator.cs @@ -17,8 +17,8 @@ public class SqlitePolygonMemberTranslator : IMemberTranslator private static readonly IDictionary MemberToFunctionName = new Dictionary { - { typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.ExteriorRing)), "ExteriorRing" }, - { typeof(Polygon).GetRequiredRuntimeProperty(nameof(Polygon.NumInteriorRings)), "NumInteriorRing" } + { typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.ExteriorRing))!, "ExteriorRing" }, + { typeof(Polygon).GetTypeInfo().GetRuntimeProperty(nameof(Polygon.NumInteriorRings))!, "NumInteriorRing" } }; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs index 6d0902dfa89..ee02f978a1e 100644 --- a/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs +++ b/src/EFCore.Sqlite.NTS/Query/Internal/SqlitePolygonMethodTranslator.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal; public class SqlitePolygonMethodTranslator : IMethodCallTranslator { private static readonly MethodInfo GetInteriorRingN - = typeof(Polygon).GetRequiredRuntimeMethod(nameof(Polygon.GetInteriorRingN), typeof(int)); + = typeof(Polygon).GetRuntimeMethod(nameof(Polygon.GetInteriorRingN), new[] { typeof(int) })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; diff --git a/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs b/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs index 01271776c43..69864db6857 100644 --- a/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs +++ b/src/EFCore.Sqlite.NTS/Scaffolding/Internal/SqliteNetTopologySuiteCodeGeneratorPlugin.cs @@ -12,9 +12,9 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal; public class SqliteNetTopologySuiteCodeGeneratorPlugin : ProviderCodeGeneratorPlugin { private static readonly MethodInfo UseNetTopologySuiteMethodInfo - = typeof(SqliteNetTopologySuiteDbContextOptionsBuilderExtensions).GetRequiredRuntimeMethod( + = typeof(SqliteNetTopologySuiteDbContextOptionsBuilderExtensions).GetRuntimeMethod( nameof(SqliteNetTopologySuiteDbContextOptionsBuilderExtensions.UseNetTopologySuite), - typeof(SqliteDbContextOptionsBuilder)); + new[] { typeof(SqliteDbContextOptionsBuilder) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/ChangeTracking/GeometryValueComparer.cs b/src/EFCore/ChangeTracking/GeometryValueComparer.cs index b9e083b89dd..6fbdd895ac7 100644 --- a/src/EFCore/ChangeTracking/GeometryValueComparer.cs +++ b/src/EFCore/ChangeTracking/GeometryValueComparer.cs @@ -49,7 +49,7 @@ public GeometryValueComparer() Expression.IsFalse(yNull), Expression.Call( x, - typeof(TGeometry).GetRequiredRuntimeMethod("EqualsExact", typeof(TGeometry)), + typeof(TGeometry).GetRuntimeMethod("EqualsExact", new[] { typeof(TGeometry) })!, y))))), left, right); @@ -61,7 +61,7 @@ private static Expression> GetSnapshotExpression() Expression body = Expression.Call( instance, - typeof(TGeometry).GetRequiredRuntimeMethod("Copy", Type.EmptyTypes)); + typeof(TGeometry).GetRuntimeMethod("Copy", Type.EmptyTypes)!); if (typeof(TGeometry).FullName != "NetTopologySuite.Geometries.Geometry") { diff --git a/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs index 89697900cc1..ab9e5768d5d 100644 --- a/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/IdentityMapFactoryFactory.cs @@ -21,7 +21,7 @@ public class IdentityMapFactoryFactory /// public virtual Func Create(IKey key) => (Func)typeof(IdentityMapFactoryFactory).GetTypeInfo() - .GetRequiredDeclaredMethod(nameof(CreateFactory)) + .GetDeclaredMethod(nameof(CreateFactory))! .MakeGenericMethod(key.GetKeyType()) .Invoke(null, new object[] { key })!; diff --git a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs index 31c0e72b09b..cc0f4bee236 100644 --- a/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs +++ b/src/EFCore/ChangeTracking/Internal/InternalEntityEntry.cs @@ -766,7 +766,7 @@ public void MarkUnknown(IProperty property) => _stateData.FlagProperty(property.GetIndex(), PropertyFlag.Unknown, true); internal static readonly MethodInfo ReadShadowValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadShadowValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadShadowValue))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -778,28 +778,28 @@ private T ReadShadowValue(int shadowIndex) => _shadowValues.GetValue(shadowIndex); internal static readonly MethodInfo ReadOriginalValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadOriginalValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadOriginalValue))!; [UsedImplicitly] private T ReadOriginalValue(IProperty property, int originalValueIndex) => _originalValues.GetValue(this, property, originalValueIndex); internal static readonly MethodInfo ReadRelationshipSnapshotValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadRelationshipSnapshotValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadRelationshipSnapshotValue))!; [UsedImplicitly] private T ReadRelationshipSnapshotValue(IPropertyBase propertyBase, int relationshipSnapshotIndex) => _relationshipsSnapshot.GetValue(this, propertyBase, relationshipSnapshotIndex); internal static readonly MethodInfo ReadStoreGeneratedValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadStoreGeneratedValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadStoreGeneratedValue))!; [UsedImplicitly] private T ReadStoreGeneratedValue(int storeGeneratedIndex) => _storeGeneratedValues.GetValue(storeGeneratedIndex); internal static readonly MethodInfo ReadTemporaryValueMethod - = typeof(InternalEntityEntry).GetTypeInfo().GetRequiredDeclaredMethod(nameof(ReadTemporaryValue)); + = typeof(InternalEntityEntry).GetTypeInfo().GetDeclaredMethod(nameof(ReadTemporaryValue))!; [UsedImplicitly] private T ReadTemporaryValue(int storeGeneratedIndex) diff --git a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs index da9c1bad15f..25654ef3949 100644 --- a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs @@ -262,7 +262,7 @@ protected virtual bool UseEntityVariable => true; private static readonly MethodInfo SnapshotCollectionMethod - = typeof(SnapshotFactoryFactory).GetTypeInfo().GetRequiredDeclaredMethod(nameof(SnapshotCollection)); + = typeof(SnapshotFactoryFactory).GetTypeInfo().GetDeclaredMethod(nameof(SnapshotCollection))!; [UsedImplicitly] private static HashSet? SnapshotCollection(IEnumerable? collection) diff --git a/src/EFCore/ChangeTracking/ValueComparer.cs b/src/EFCore/ChangeTracking/ValueComparer.cs index e93224c2c5a..29d3e852b08 100644 --- a/src/EFCore/ChangeTracking/ValueComparer.cs +++ b/src/EFCore/ChangeTracking/ValueComparer.cs @@ -26,25 +26,25 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking; public abstract class ValueComparer : IEqualityComparer, IEqualityComparer { private static readonly MethodInfo DoubleEqualsMethodInfo - = typeof(double).GetRequiredRuntimeMethod(nameof(double.Equals), typeof(double)); + = typeof(double).GetRuntimeMethod(nameof(double.Equals), new[] { typeof(double) })!; private static readonly MethodInfo FloatEqualsMethodInfo - = typeof(float).GetRequiredRuntimeMethod(nameof(float.Equals), typeof(float)); + = typeof(float).GetRuntimeMethod(nameof(float.Equals), new[] { typeof(float) })!; internal static readonly MethodInfo ArrayCopyMethod - = typeof(Array).GetRequiredRuntimeMethod(nameof(Array.Copy), typeof(Array), typeof(Array), typeof(int)); + = typeof(Array).GetRuntimeMethod(nameof(Array.Copy), new[] { typeof(Array), typeof(Array), typeof(int) })!; internal static readonly MethodInfo EqualityComparerHashCodeMethod - = typeof(IEqualityComparer).GetRequiredRuntimeMethod(nameof(IEqualityComparer.GetHashCode), typeof(object)); + = typeof(IEqualityComparer).GetRuntimeMethod(nameof(IEqualityComparer.GetHashCode), new[] { typeof(object) })!; internal static readonly MethodInfo EqualityComparerEqualsMethod - = typeof(IEqualityComparer).GetRequiredRuntimeMethod(nameof(IEqualityComparer.Equals), typeof(object), typeof(object)); + = typeof(IEqualityComparer).GetRuntimeMethod(nameof(IEqualityComparer.Equals), new[] { typeof(object), typeof(object) })!; internal static readonly MethodInfo ObjectEqualsMethod - = typeof(object).GetRequiredRuntimeMethod(nameof(object.Equals), typeof(object), typeof(object)); + = typeof(object).GetRuntimeMethod(nameof(object.Equals), new[] { typeof(object), typeof(object) })!; internal static readonly MethodInfo ObjectGetHashCodeMethod - = typeof(object).GetRequiredRuntimeMethod(nameof(object.GetHashCode), Type.EmptyTypes); + = typeof(object).GetRuntimeMethod(nameof(object.GetHashCode), Type.EmptyTypes)!; /// /// Creates a new with the given comparison and @@ -273,7 +273,7 @@ public override Expression ExtractEqualsBody(Expression leftExpression, Expressi internal sealed class DefaultDateTimeOffsetValueComparer : DefaultValueComparer { private static readonly MethodInfo EqualsExactMethodInfo - = typeof(DateTimeOffset).GetRequiredRuntimeMethod(nameof(DateTimeOffset.EqualsExact), typeof(DateTimeOffset)); + = typeof(DateTimeOffset).GetRuntimeMethod(nameof(DateTimeOffset.EqualsExact), new[] { typeof(DateTimeOffset) })!; // In .NET, two DateTimeOffset instances are considered equal if they represent the same point in time but with different // time zone offsets. This comparer uses EqualsExact, which considers such DateTimeOffset as non-equal. diff --git a/src/EFCore/ChangeTracking/ValueComparer`.cs b/src/EFCore/ChangeTracking/ValueComparer`.cs index f6b767ebca3..99f743569d1 100644 --- a/src/EFCore/ChangeTracking/ValueComparer`.cs +++ b/src/EFCore/ChangeTracking/ValueComparer`.cs @@ -191,7 +191,7 @@ protected static Expression> CreateDefaultSnapshotExpression(bool fav new[] { lengthVariable, destinationVariable }, Expression.Assign( lengthVariable, - Expression.Property(sourceParameter, typeof(T).GetRequiredProperty(nameof(Array.Length)))), + Expression.Property(sourceParameter, typeof(T).GetTypeInfo().GetProperty(nameof(Array.Length))!)), Expression.Assign( destinationVariable, Expression.NewArrayBounds(typeof(T).GetSequenceType(), lengthVariable)), diff --git a/src/EFCore/EF.cs b/src/EFCore/EF.cs index 29bb70788d4..457cc47efda 100644 --- a/src/EFCore/EF.cs +++ b/src/EFCore/EF.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore; public static partial class EF { internal static readonly MethodInfo PropertyMethod - = typeof(EF).GetRequiredDeclaredMethod(nameof(Property)); + = typeof(EF).GetTypeInfo().GetDeclaredMethod(nameof(Property))!; /// /// References a given property or navigation on an entity instance. This is useful for shadow state properties, for diff --git a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs index 69c9525899d..45593dfe27e 100644 --- a/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs +++ b/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs @@ -2473,8 +2473,7 @@ source.Provider is EntityQueryProvider #region Auto included navigations internal static readonly MethodInfo IgnoreAutoIncludesMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(IgnoreAutoIncludes)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(IgnoreAutoIncludes))!; /// /// Specifies that the current Entity Framework LINQ query should not have any model-level eager loaded navigations applied. @@ -2501,8 +2500,7 @@ public static IQueryable IgnoreAutoIncludes( #region Query Filters internal static readonly MethodInfo IgnoreQueryFiltersMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(IgnoreQueryFilters)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(IgnoreQueryFilters))!; /// /// Specifies that the current Entity Framework LINQ query should not have any model-level entity query filters applied. @@ -2530,8 +2528,7 @@ public static IQueryable IgnoreQueryFilters( #region Tracking internal static readonly MethodInfo AsNoTrackingMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(AsNoTracking)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsNoTracking))!; /// /// The change tracker will not track any of the entities that are returned from a LINQ query. If the @@ -2572,8 +2569,7 @@ public static IQueryable AsNoTracking( : source; internal static readonly MethodInfo AsNoTrackingWithIdentityResolutionMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod(nameof(AsNoTrackingWithIdentityResolution)); + = typeof(EntityFrameworkQueryableExtensions).GetTypeInfo().GetDeclaredMethod(nameof(AsNoTrackingWithIdentityResolution))!; /// /// The change tracker will not track any of the entities that are returned from a LINQ query. If the @@ -2691,19 +2687,20 @@ public static IQueryable AsTracking( #region Tagging internal static readonly MethodInfo TagWithMethodInfo - = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod( - nameof(TagWith), mi => mi.GetParameters().Length == 2 - && mi.GetParameters().Select(p => p.ParameterType) - .SequenceEqual(new[] { typeof(IQueryable<>).MakeGenericType(mi.GetGenericArguments()), typeof(string) })); + = typeof(EntityFrameworkQueryableExtensions).GetMethod(nameof(TagWith), new[] + { + typeof(IQueryable<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), + typeof(string) + })!; internal static readonly MethodInfo TagWithCallSiteMethodInfo = typeof(EntityFrameworkQueryableExtensions) - .GetRequiredDeclaredMethod( - nameof(TagWithCallSite), mi => mi.GetParameters().Length == 3 - && mi.GetParameters().Select(p => p.ParameterType) - .SequenceEqual( - new[] { typeof(IQueryable<>).MakeGenericType(mi.GetGenericArguments()), typeof(string), typeof(int) })); + .GetMethod(nameof(TagWithCallSite), new[] + { + typeof(IQueryable<>).MakeGenericType(Type.MakeGenericMethodParameter(0)), + typeof(string), + typeof(int) + })!; /// /// Adds a tag to the collection of tags associated with an EF LINQ query. Tags are query annotations diff --git a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs index a6ee5cdc7fd..fe8b95eb478 100644 --- a/src/EFCore/Extensions/Internal/ExpressionExtensions.cs +++ b/src/EFCore/Extensions/Internal/ExpressionExtensions.cs @@ -37,7 +37,8 @@ public static Expression MakeHasDefaultValue( return Expression.Not( Expression.Call( currentValueExpression, - currentValueExpression.Type.GetRequiredMethod("get_HasValue"))); + Check.NotNull( + currentValueExpression.Type.GetMethod("get_HasValue"), $"get_HasValue on {currentValueExpression.Type.Name}"))); } var property = propertyBase as IReadOnlyProperty; @@ -193,7 +194,7 @@ public static bool IsLogicalNot(this UnaryExpression sqlUnaryExpression) } private static readonly MethodInfo ObjectEqualsMethodInfo - = typeof(object).GetRequiredRuntimeMethod(nameof(object.Equals), typeof(object), typeof(object)); + = typeof(object).GetRuntimeMethod(nameof(object.Equals), new[] { typeof(object), typeof(object) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Infrastructure/ExpressionExtensions.cs b/src/EFCore/Infrastructure/ExpressionExtensions.cs index 6043f8d20b3..98be1707106 100644 --- a/src/EFCore/Infrastructure/ExpressionExtensions.cs +++ b/src/EFCore/Infrastructure/ExpressionExtensions.cs @@ -299,7 +299,7 @@ public static Expression CreateValueBufferReadValueExpression( /// /// public static readonly MethodInfo ValueBufferTryReadValueMethod - = typeof(ExpressionExtensions).GetRequiredDeclaredMethod(nameof(ValueBufferTryReadValue)); + = typeof(ExpressionExtensions).GetTypeInfo().GetDeclaredMethod(nameof(ValueBufferTryReadValue))!; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static TValue ValueBufferTryReadValue( diff --git a/src/EFCore/Internal/DbSetSource.cs b/src/EFCore/Internal/DbSetSource.cs index d50422da54a..d66eb09291d 100644 --- a/src/EFCore/Internal/DbSetSource.cs +++ b/src/EFCore/Internal/DbSetSource.cs @@ -15,7 +15,7 @@ namespace Microsoft.EntityFrameworkCore.Internal; public class DbSetSource : IDbSetSource { private static readonly MethodInfo GenericCreateSet - = typeof(DbSetSource).GetTypeInfo().GetRequiredDeclaredMethod(nameof(CreateSetFactory)); + = typeof(DbSetSource).GetTypeInfo().GetDeclaredMethod(nameof(CreateSetFactory))!; private readonly ConcurrentDictionary<(Type Type, string? Name), Func> _cache = new(); diff --git a/src/EFCore/Internal/EntityFinderSource.cs b/src/EFCore/Internal/EntityFinderSource.cs index e7d45092ba7..b1692e4e6dc 100644 --- a/src/EFCore/Internal/EntityFinderSource.cs +++ b/src/EFCore/Internal/EntityFinderSource.cs @@ -16,7 +16,7 @@ namespace Microsoft.EntityFrameworkCore.Internal; public class EntityFinderSource : IEntityFinderSource { private static readonly MethodInfo GenericCreate - = typeof(EntityFinderSource).GetTypeInfo().GetRequiredDeclaredMethod(nameof(CreateConstructor)); + = typeof(EntityFinderSource).GetTypeInfo().GetDeclaredMethod(nameof(CreateConstructor))!; private readonly ConcurrentDictionary> _cache = new(); diff --git a/src/EFCore/Internal/ManyToManyLoaderFactory.cs b/src/EFCore/Internal/ManyToManyLoaderFactory.cs index c325527b57c..05953b2b651 100644 --- a/src/EFCore/Internal/ManyToManyLoaderFactory.cs +++ b/src/EFCore/Internal/ManyToManyLoaderFactory.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Internal; public class ManyToManyLoaderFactory { private static readonly MethodInfo GenericCreate - = typeof(ManyToManyLoaderFactory).GetTypeInfo().GetRequiredDeclaredMethod(nameof(CreateManyToMany)); + = typeof(ManyToManyLoaderFactory).GetTypeInfo().GetDeclaredMethod(nameof(CreateManyToMany))!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs b/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs index e37c3f0a4ca..37a8334f093 100644 --- a/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs +++ b/src/EFCore/Metadata/Conventions/EntityTypeConfigurationEntityTypeAttributeConvention.cs @@ -11,8 +11,8 @@ namespace Microsoft.EntityFrameworkCore.Metadata.Conventions; /// public class EntityTypeConfigurationEntityTypeAttributeConvention : EntityTypeAttributeConventionBase { - private static readonly MethodInfo ConfigureMethod = typeof(EntityTypeConfigurationEntityTypeAttributeConvention) - .GetRequiredDeclaredMethod(nameof(Configure)); + private static readonly MethodInfo ConfigureMethod + = typeof(EntityTypeConfigurationEntityTypeAttributeConvention).GetTypeInfo().GetDeclaredMethod(nameof(Configure))!; /// /// Creates a new instance of . diff --git a/src/EFCore/Metadata/Internal/PropertyBase.cs b/src/EFCore/Metadata/Internal/PropertyBase.cs index d70a8a220f1..0a604920be5 100644 --- a/src/EFCore/Metadata/Internal/PropertyBase.cs +++ b/src/EFCore/Metadata/Internal/PropertyBase.cs @@ -411,7 +411,7 @@ public virtual IComparer CurrentValueComparer }); private static readonly MethodInfo ContainsKeyMethod = - typeof(IDictionary).GetRequiredMethod(nameof(IDictionary.ContainsKey), typeof(string)); + typeof(IDictionary).GetMethod(nameof(IDictionary.ContainsKey), new[] { typeof(string) })!; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to diff --git a/src/EFCore/Query/EntityShaperExpression.cs b/src/EFCore/Query/EntityShaperExpression.cs index c3f0c3910b8..a6bf2d66416 100644 --- a/src/EFCore/Query/EntityShaperExpression.cs +++ b/src/EFCore/Query/EntityShaperExpression.cs @@ -21,7 +21,7 @@ namespace Microsoft.EntityFrameworkCore.Query; public class EntityShaperExpression : Expression, IPrintableExpression { private static readonly MethodInfo CreateUnableToDiscriminateExceptionMethod - = typeof(EntityShaperExpression).GetRequiredDeclaredMethod(nameof(CreateUnableToDiscriminateException)); + = typeof(EntityShaperExpression).GetTypeInfo().GetDeclaredMethod(nameof(CreateUnableToDiscriminateException))!; [UsedImplicitly] private static Exception CreateUnableToDiscriminateException(IEntityType entityType, object discriminator) diff --git a/src/EFCore/Query/EvaluatableExpressionFilter.cs b/src/EFCore/Query/EvaluatableExpressionFilter.cs index 514afce7b5e..0ebacc36520 100644 --- a/src/EFCore/Query/EvaluatableExpressionFilter.cs +++ b/src/EFCore/Query/EvaluatableExpressionFilter.cs @@ -23,31 +23,31 @@ public class EvaluatableExpressionFilter : IEvaluatableExpressionFilter // Hence we don't evaluate them. See issue#2069 private static readonly PropertyInfo DateTimeNow - = typeof(DateTime).GetRequiredDeclaredProperty(nameof(DateTime.Now)); + = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.Now))!; private static readonly PropertyInfo DateTimeUtcNow - = typeof(DateTime).GetRequiredDeclaredProperty(nameof(DateTime.UtcNow)); + = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.UtcNow))!; private static readonly PropertyInfo DateTimeToday - = typeof(DateTime).GetRequiredDeclaredProperty(nameof(DateTime.Today)); + = typeof(DateTime).GetTypeInfo().GetDeclaredProperty(nameof(DateTime.Today))!; private static readonly PropertyInfo DateTimeOffsetNow - = typeof(DateTimeOffset).GetRequiredDeclaredProperty(nameof(DateTimeOffset.Now)); + = typeof(DateTimeOffset).GetTypeInfo().GetDeclaredProperty(nameof(DateTimeOffset.Now))!; private static readonly PropertyInfo DateTimeOffsetUtcNow - = typeof(DateTimeOffset).GetRequiredDeclaredProperty(nameof(DateTimeOffset.UtcNow)); + = typeof(DateTimeOffset).GetTypeInfo().GetDeclaredProperty(nameof(DateTimeOffset.UtcNow))!; private static readonly MethodInfo GuidNewGuid - = typeof(Guid).GetRequiredDeclaredMethod(nameof(Guid.NewGuid)); + = typeof(Guid).GetTypeInfo().GetDeclaredMethod(nameof(Guid.NewGuid))!; private static readonly MethodInfo RandomNextNoArgs - = typeof(Random).GetRequiredRuntimeMethod(nameof(Random.Next), Array.Empty()); + = typeof(Random).GetRuntimeMethod(nameof(Random.Next), Type.EmptyTypes)!; private static readonly MethodInfo RandomNextOneArg - = typeof(Random).GetRequiredRuntimeMethod(nameof(Random.Next), typeof(int)); + = typeof(Random).GetRuntimeMethod(nameof(Random.Next), new[] { typeof(int) })!; private static readonly MethodInfo RandomNextTwoArgs - = typeof(Random).GetRequiredRuntimeMethod(nameof(Random.Next), typeof(int), typeof(int)); + = typeof(Random).GetRuntimeMethod(nameof(Random.Next), new[] { typeof(int), typeof(int) })!; /// /// diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs index 83edd382d40..db4a1fca558 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.ExpressionVisitors.cs @@ -15,7 +15,7 @@ public partial class NavigationExpandingExpressionVisitor private class ExpandingExpressionVisitor : ExpressionVisitor { private static readonly MethodInfo ObjectEqualsMethodInfo - = typeof(object).GetRequiredRuntimeMethod(nameof(object.Equals), typeof(object), typeof(object)); + = typeof(object).GetRuntimeMethod(nameof(object.Equals), new[] { typeof(object), typeof(object) })!; private readonly NavigationExpandingExpressionVisitor _navigationExpandingExpressionVisitor; private readonly NavigationExpansionExpression _source; @@ -430,8 +430,8 @@ outerKey is NewArrayExpression newArrayExpression var resultSelectorInnerParameter = Expression.Parameter(innerSource.SourceElementType, "i"); var resultType = TransparentIdentifierFactory.Create(_source.SourceElementType, innerSource.SourceElementType); - var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner")!; var resultSelector = Expression.Lambda( Expression.New( @@ -487,7 +487,7 @@ private static Expression AddConvertToObject(Expression expression) private sealed class IncludeExpandingExpressionVisitor : ExpandingExpressionVisitor { private static readonly MethodInfo FetchJoinEntityMethodInfo = - typeof(IncludeExpandingExpressionVisitor).GetRequiredDeclaredMethod(nameof(FetchJoinEntity)); + typeof(IncludeExpandingExpressionVisitor).GetTypeInfo().GetDeclaredMethod(nameof(FetchJoinEntity))!; private readonly bool _queryStateManager; private readonly bool _ignoreAutoIncludes; @@ -821,8 +821,8 @@ private Expression ExpandIncludesHelper(Expression root, EntityReference entityR { var resultType = TransparentIdentifierFactory.Create(joinParameter.Type, targetParameter.Type); - var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = resultType.GetTypeInfo().GetDeclaredField("Inner")!; var newResultSelector = Expression.Quote( Expression.Lambda( @@ -1135,9 +1135,9 @@ public GroupingElementReplacingExpressionVisitor( _navigationExpansionExpression = (NavigationExpansionExpression)groupByNavigationExpansionExpression.GroupingEnumerable; _keyAccessExpression = Expression.MakeMemberAccess( groupByNavigationExpansionExpression.CurrentParameter, - groupByNavigationExpansionExpression.CurrentParameter.Type.GetRequiredDeclaredProperty( - nameof(IGrouping.Key))); - _keyMemberInfo = parameterExpression.Type.GetRequiredDeclaredProperty(nameof(IGrouping.Key)); + groupByNavigationExpansionExpression.CurrentParameter.Type.GetTypeInfo().GetDeclaredProperty( + nameof(IGrouping.Key))!); + _keyMemberInfo = parameterExpression.Type.GetTypeInfo().GetDeclaredProperty(nameof(IGrouping.Key))!; _cloningExpressionVisitor = new CloningExpressionVisitor(); } diff --git a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs index 9e552d4c07b..7894cc19e0e 100644 --- a/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/NavigationExpandingExpressionVisitor.cs @@ -14,7 +14,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public partial class NavigationExpandingExpressionVisitor : ExpressionVisitor { private static readonly PropertyInfo QueryContextContextPropertyInfo - = typeof(QueryContext).GetRequiredDeclaredProperty(nameof(QueryContext.Context)); + = typeof(QueryContext).GetTypeInfo().GetDeclaredProperty(nameof(QueryContext.Context))!; private static readonly Dictionary PredicateLessMethodInfo = new() { @@ -1135,8 +1135,8 @@ private NavigationExpansionExpression ProcessJoin( var transparentIdentifierType = TransparentIdentifierFactory.Create( outerSource.SourceElementType, innerSource.SourceElementType); - var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var newResultSelector = Expression.Lambda( Expression.New( @@ -1184,8 +1184,8 @@ private NavigationExpansionExpression ProcessLeftJoin( var transparentIdentifierType = TransparentIdentifierFactory.Create( outerSource.SourceElementType, innerSource.SourceElementType); - var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var newResultSelector = Expression.Lambda( Expression.New( @@ -1295,8 +1295,8 @@ private NavigationExpansionExpression ProcessSelectMany( var transparentIdentifierType = TransparentIdentifierFactory.Create( source.SourceElementType, collectionElementType); - var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Outer"); - var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetRequiredDeclaredField("Inner"); + var transparentIdentifierOuterMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Outer")!; + var transparentIdentifierInnerMemberInfo = transparentIdentifierType.GetTypeInfo().GetDeclaredField("Inner")!; var collectionElementParameter = Expression.Parameter(collectionElementType, "c"); var newResultSelector = Expression.Lambda( diff --git a/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs b/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs index d1dde327f04..0b4450255a6 100644 --- a/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs +++ b/src/EFCore/Query/Internal/QueryOptimizingExpressionVisitor.cs @@ -33,16 +33,16 @@ public class QueryOptimizingExpressionVisitor : ExpressionVisitor }; private static readonly MethodInfo StringCompareWithComparisonMethod = - typeof(string).GetRequiredRuntimeMethod(nameof(string.Compare), typeof(string), typeof(string), typeof(StringComparison)); + typeof(string).GetRuntimeMethod(nameof(string.Compare), new[] { typeof(string), typeof(string), typeof(StringComparison) })!; private static readonly MethodInfo StringCompareWithoutComparisonMethod = - typeof(string).GetRequiredRuntimeMethod(nameof(string.Compare), typeof(string), typeof(string)); + typeof(string).GetRuntimeMethod(nameof(string.Compare), new[] { typeof(string), typeof(string) })!; private static readonly MethodInfo StartsWithMethodInfo = - typeof(string).GetRequiredRuntimeMethod(nameof(string.StartsWith), typeof(string)); + typeof(string).GetRuntimeMethod(nameof(string.StartsWith), new[] { typeof(string) })!; private static readonly MethodInfo EndsWithMethodInfo = - typeof(string).GetRequiredRuntimeMethod(nameof(string.EndsWith), typeof(string)); + typeof(string).GetRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) })!; private static readonly Expression ConstantNullString = Expression.Constant(null, typeof(string)); diff --git a/src/EFCore/Query/QueryCompilationContext.cs b/src/EFCore/Query/QueryCompilationContext.cs index 85890b004ae..762bdbd2dfb 100644 --- a/src/EFCore/Query/QueryCompilationContext.cs +++ b/src/EFCore/Query/QueryCompilationContext.cs @@ -219,7 +219,7 @@ private Expression InsertRuntimeParameters(Expression query) .Append(query)); private static readonly MethodInfo QueryContextAddParameterMethodInfo - = typeof(QueryContext).GetRequiredDeclaredMethod(nameof(QueryContext.AddParameter)); + = typeof(QueryContext).GetTypeInfo().GetDeclaredMethod(nameof(QueryContext.AddParameter))!; private sealed class NotTranslatedExpressionType : Expression { diff --git a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs index f1e17838c45..9ab1f5d35d1 100644 --- a/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs +++ b/src/EFCore/Query/ShapedQueryCompilingExpressionVisitor.cs @@ -33,7 +33,7 @@ namespace Microsoft.EntityFrameworkCore.Query; public abstract class ShapedQueryCompilingExpressionVisitor : ExpressionVisitor { private static readonly PropertyInfo CancellationTokenMemberInfo - = typeof(QueryContext).GetRequiredProperty(nameof(QueryContext.CancellationToken)); + = typeof(QueryContext).GetTypeInfo().GetProperty(nameof(QueryContext.CancellationToken))!; private readonly Expression _cancellationTokenParameter; private readonly EntityMaterializerInjectingExpressionVisitor _entityMaterializerInjectingExpressionVisitor; @@ -278,25 +278,25 @@ private static readonly ConstructorInfo ValueBufferConstructor = typeof(ValueBuffer).GetTypeInfo().DeclaredConstructors.Single(ci => ci.GetParameters().Length == 1); private static readonly PropertyInfo DbContextMemberInfo - = typeof(QueryContext).GetRequiredProperty(nameof(QueryContext.Context)); + = typeof(QueryContext).GetTypeInfo().GetProperty(nameof(QueryContext.Context))!; private static readonly PropertyInfo EntityMemberInfo - = typeof(InternalEntityEntry).GetRequiredProperty(nameof(InternalEntityEntry.Entity)); + = typeof(InternalEntityEntry).GetTypeInfo().GetProperty(nameof(InternalEntityEntry.Entity))!; private static readonly PropertyInfo EntityTypeMemberInfo - = typeof(InternalEntityEntry).GetRequiredProperty(nameof(InternalEntityEntry.EntityType)); + = typeof(InternalEntityEntry).GetTypeInfo().GetProperty(nameof(InternalEntityEntry.EntityType))!; private static readonly MethodInfo TryGetEntryMethodInfo = typeof(QueryContext).GetTypeInfo().GetDeclaredMethods(nameof(QueryContext.TryGetEntry)) .Single(mi => mi.GetParameters().Length == 4); private static readonly MethodInfo StartTrackingMethodInfo - = typeof(QueryContext).GetRequiredMethod( - nameof(QueryContext.StartTracking), typeof(IEntityType), typeof(object), typeof(ValueBuffer)); + = typeof(QueryContext).GetMethod( + nameof(QueryContext.StartTracking), new[] { typeof(IEntityType), typeof(object), typeof(ValueBuffer) })!; private static readonly MethodInfo CreateNullKeyValueInNoTrackingQueryMethod - = typeof(EntityMaterializerInjectingExpressionVisitor).GetRequiredDeclaredMethod( - nameof(CreateNullKeyValueInNoTrackingQuery)); + = typeof(EntityMaterializerInjectingExpressionVisitor) + .GetTypeInfo().GetDeclaredMethod(nameof(CreateNullKeyValueInNoTrackingQuery))!; private readonly IEntityMaterializerSource _entityMaterializerSource; private readonly QueryTrackingBehavior _queryTrackingBehavior; diff --git a/src/Shared/SharedTypeExtensions.cs b/src/Shared/SharedTypeExtensions.cs index 931fedce875..50778d10f3f 100644 --- a/src/Shared/SharedTypeExtensions.cs +++ b/src/Shared/SharedTypeExtensions.cs @@ -117,51 +117,6 @@ public static bool IsAnonymousType(this Type type) return props.SingleOrDefault(); } - public static MethodInfo GetRequiredMethod(this Type type, string name, params Type[] parameters) - { - var method = type.GetTypeInfo().GetMethod(name, parameters); - - if (method == null - && parameters.Length == 0) - { - method = type.GetMethod(name); - } - - if (method == null) - { - throw new InvalidOperationException(); - } - - return method; - } - - public static PropertyInfo GetRequiredProperty(this Type type, string name) - => type.GetTypeInfo().GetProperty(name) - ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); - - public static FieldInfo GetRequiredDeclaredField(this Type type, string name) - => type.GetTypeInfo().GetDeclaredField(name) - ?? throw new InvalidOperationException($"Could not find field '{name}' on type '{type}'"); - - public static MethodInfo GetRequiredDeclaredMethod(this Type type, string name) - => type.GetTypeInfo().GetDeclaredMethod(name) - ?? throw new InvalidOperationException($"Could not find method '{name}' on type '{type}'"); - - public static MethodInfo GetRequiredDeclaredMethod(this Type type, string name, Func methodSelector) - => type.GetTypeInfo().GetDeclaredMethods(name).Single(methodSelector); - - public static PropertyInfo GetRequiredDeclaredProperty(this Type type, string name) - => type.GetTypeInfo().GetDeclaredProperty(name) - ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); - - public static MethodInfo GetRequiredRuntimeMethod(this Type type, string name, params Type[] parameters) - => type.GetTypeInfo().GetRuntimeMethod(name, parameters) - ?? throw new InvalidOperationException($"Could not find method '{name}' on type '{type}'"); - - public static PropertyInfo GetRequiredRuntimeProperty(this Type type, string name) - => type.GetTypeInfo().GetRuntimeProperty(name) - ?? throw new InvalidOperationException($"Could not find property '{name}' on type '{type}'"); - public static bool IsInstantiable(this Type type) => !type.IsAbstract && !type.IsInterface diff --git a/test/EFCore.Relational.Tests/TestUtilities/TestProviderCodeGenerator.cs b/test/EFCore.Relational.Tests/TestUtilities/TestProviderCodeGenerator.cs index 8b3ca185279..2ecb98f6100 100644 --- a/test/EFCore.Relational.Tests/TestUtilities/TestProviderCodeGenerator.cs +++ b/test/EFCore.Relational.Tests/TestUtilities/TestProviderCodeGenerator.cs @@ -20,8 +20,8 @@ public override MethodCallCodeFragment GenerateUseProvider( : new object[] { connectionString, new NestedClosureCodeFragment("x", providerOptions) }); private static readonly MethodInfo _useTestProviderMethodInfo - = typeof(TestProviderCodeGenerator).GetRequiredRuntimeMethod( - nameof(UseTestProvider), typeof(DbContextOptionsBuilder), typeof(string), typeof(Action)); + = typeof(TestProviderCodeGenerator).GetRuntimeMethod( + nameof(UseTestProvider), new[] { typeof(DbContextOptionsBuilder), typeof(string), typeof(Action) })!; public static void UseTestProvider( DbContextOptionsBuilder optionsBuilder, diff --git a/test/EFCore.Tests/Design/MethodCallCodeFragmentTest.cs b/test/EFCore.Tests/Design/MethodCallCodeFragmentTest.cs index 992b4604c48..4546ab9af8a 100644 --- a/test/EFCore.Tests/Design/MethodCallCodeFragmentTest.cs +++ b/test/EFCore.Tests/Design/MethodCallCodeFragmentTest.cs @@ -20,10 +20,10 @@ public virtual void Ctor_throw_when_too_many_parameters_instance() } private static readonly MethodInfo _extensionFuncMethodInfo - = typeof(MethodCallCodeFragmentTest).GetRequiredRuntimeMethod(nameof(ExtensionFunc), typeof(object), typeof(int)); + = typeof(MethodCallCodeFragmentTest).GetRuntimeMethod(nameof(ExtensionFunc), new[] { typeof(object), typeof(int) })!; private static readonly MethodInfo _instanceFuncMethodInfo - = typeof(MethodCallCodeFragmentTest).GetRequiredRuntimeMethod(nameof(InstanceFunc), typeof(int)); + = typeof(MethodCallCodeFragmentTest).GetRuntimeMethod(nameof(InstanceFunc), new[] { typeof(int) })!; public static void ExtensionFunc(object thisParameter, int p) => throw new NotSupportedException(); diff --git a/test/EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj b/test/EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj new file mode 100644 index 00000000000..77de174db4a --- /dev/null +++ b/test/EFCore.Trimming.Tests/EFCore.Trimming.Tests.csproj @@ -0,0 +1,19 @@ + + + + Exe + net6.0 + true + false + + + + + + + + + + + + diff --git a/test/EFCore.Trimming.Tests/Program.cs b/test/EFCore.Trimming.Tests/Program.cs new file mode 100644 index 00000000000..7d7d2e557ea --- /dev/null +++ b/test/EFCore.Trimming.Tests/Program.cs @@ -0,0 +1,44 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Linq; +using EFCore.Trimming.Tests; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; + +await using var ctx = new BlogContext(); +await ctx.Database.EnsureDeletedAsync(); +await ctx.Database.EnsureCreatedAsync(); + +// Execute any query to make sure the basic query pipeline works +_ = ctx.Blogs.Where(b => b.Name.StartsWith("foo")).ToList(); + +Console.WriteLine("Database query executed successfully."); + +public class BlogContext : DbContext +{ + private static readonly string ConnectionString; + + public DbSet Blogs { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + => optionsBuilder.UseSqlServer(ConnectionString); + + static BlogContext() + { + var builder = new SqlConnectionStringBuilder(TestEnvironment.DefaultConnection) + { + InitialCatalog = "TrimmingTests" + }; + + ConnectionString = builder.ToString(); + } +} + +public class Blog +{ + public int Id { get; set; } + public string Name { get; set; } +} + diff --git a/test/EFCore.Trimming.Tests/TestEnvironment.cs b/test/EFCore.Trimming.Tests/TestEnvironment.cs new file mode 100644 index 00000000000..2edb5e22f26 --- /dev/null +++ b/test/EFCore.Trimming.Tests/TestEnvironment.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.IO; +using Microsoft.Extensions.Configuration; + +namespace EFCore.Trimming.Tests; + +public static class TestEnvironment +{ + public static IConfiguration Config { get; } = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("config.json", optional: true) + .AddJsonFile("config.test.json", optional: true) + .AddEnvironmentVariables() + .Build() + .GetSection("Test:SqlServer"); + + public static string DefaultConnection { get; } = Config["DefaultConnection"] + ?? "Data Source=(localdb)\\MSSQLLocalDB;Database=master;Integrated Security=True;Connect Timeout=60;ConnectRetryCount=0"; +}