From 56841ceb10fa51d694eb7f9520781f827c490854 Mon Sep 17 00:00:00 2001 From: danevandy99 Date: Mon, 27 May 2024 17:57:17 -0500 Subject: [PATCH] Translate ToString() over enums Fixes #33635 and #20604 --- ...yExpressionTranslatingExpressionVisitor.cs | 7 +- ...gTranslator.cs => EnumMethodTranslator.cs} | 44 ++++- .../RelationalMethodCallTranslatorProvider.cs | 2 +- .../SqlServerObjectToStringTranslator.cs | 2 + .../SqliteObjectToStringTranslator.cs | 2 + .../Query/GearsOfWarQueryFixtureBase.cs | 7 +- .../Query/GearsOfWarQueryTestBase.cs | 38 +++-- .../GearsOfWarModel/GearsOfWarData.cs | 9 +- .../TestModels/GearsOfWarModel/Mission.cs | 1 + .../GearsOfWarModel/MissionDifficulty.cs | 13 ++ .../Query/GearsOfWarQuerySqlServerTest.cs | 151 ++++++++++++------ .../Query/TPCGearsOfWarQuerySqlServerTest.cs | 137 +++++++++++----- .../Query/TPTGearsOfWarQuerySqlServerTest.cs | 133 ++++++++++----- .../TemporalGearsOfWarQuerySqlServerTest.cs | 147 +++++++++++------ .../Query/GearsOfWarQuerySqliteTest.cs | 99 +++++++++--- 15 files changed, 569 insertions(+), 223 deletions(-) rename src/EFCore.Relational/Query/Internal/Translators/{EnumHasFlagTranslator.cs => EnumMethodTranslator.cs} (53%) create mode 100644 test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/MissionDifficulty.cs diff --git a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs index a5c33c32481..6234496a5f2 100644 --- a/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs +++ b/src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs @@ -882,10 +882,13 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp } // if object is nullable, add null safeguard before calling the function - // we special-case Nullable<>.GetValueOrDefault, which doesn't need the safeguard + // we special-case Nullable<>.GetValueOrDefault, which doesn't need the safeguard, + // and Nullable<>.ToString when the object is a nullable value type. if (methodCallExpression.Object != null && @object!.Type.IsNullableType() - && methodCallExpression.Method.Name != nameof(Nullable.GetValueOrDefault)) + && methodCallExpression.Method.Name != nameof(Nullable.GetValueOrDefault) + && (!@object!.Type.IsNullableValueType() + || methodCallExpression.Method.Name != nameof(Nullable.ToString))) { var result = (Expression)methodCallExpression.Update( Expression.Convert(@object, methodCallExpression.Object.Type), diff --git a/src/EFCore.Relational/Query/Internal/Translators/EnumHasFlagTranslator.cs b/src/EFCore.Relational/Query/Internal/Translators/EnumMethodTranslator.cs similarity index 53% rename from src/EFCore.Relational/Query/Internal/Translators/EnumHasFlagTranslator.cs rename to src/EFCore.Relational/Query/Internal/Translators/EnumMethodTranslator.cs index dbf6db241f2..ef8811a8d0f 100644 --- a/src/EFCore.Relational/Query/Internal/Translators/EnumHasFlagTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/Translators/EnumMethodTranslator.cs @@ -12,10 +12,13 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// -public class EnumHasFlagTranslator : IMethodCallTranslator +public class EnumMethodTranslator : IMethodCallTranslator { - private static readonly MethodInfo MethodInfo - = typeof(Enum).GetRuntimeMethod(nameof(Enum.HasFlag), [typeof(Enum)])!; + private static readonly MethodInfo HasFlagMethodInfo + = typeof(Enum).GetRuntimeMethod(nameof(Enum.HasFlag), new[] { typeof(Enum) })!; + + private static readonly MethodInfo ToStringMethodInfo + = typeof(object).GetRuntimeMethod(nameof(ToString), new Type[] { })!; private readonly ISqlExpressionFactory _sqlExpressionFactory; @@ -25,7 +28,7 @@ private static readonly MethodInfo MethodInfo /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public EnumHasFlagTranslator(ISqlExpressionFactory sqlExpressionFactory) + public EnumMethodTranslator(ISqlExpressionFactory sqlExpressionFactory) { _sqlExpressionFactory = sqlExpressionFactory; } @@ -42,7 +45,7 @@ public EnumHasFlagTranslator(ISqlExpressionFactory sqlExpressionFactory) IReadOnlyList arguments, IDiagnosticsLogger logger) { - if (Equals(method, MethodInfo) + if (Equals(method, HasFlagMethodInfo) && instance != null) { var argument = arguments[0]; @@ -51,6 +54,37 @@ public EnumHasFlagTranslator(ISqlExpressionFactory sqlExpressionFactory) : _sqlExpressionFactory.Equal(_sqlExpressionFactory.And(instance, argument), argument); } + if (Equals(method, ToStringMethodInfo) + && instance != null + && instance.Type.IsEnum) + { + var converterType = instance.TypeMapping?.Converter?.GetType(); + + if (converterType is not null + && converterType.IsGenericType) + { + if (converterType.GetGenericTypeDefinition() == typeof(EnumToNumberConverter<,>) + && converterType.GetGenericArguments().Length == 2 + && converterType.GetGenericArguments()[1] == typeof(int) + && (instance is SqlParameterExpression || instance is ColumnExpression)) + { + var cases = Enum.GetValues(instance.Type) + .Cast() + .Select(value => new CaseWhenClause( + _sqlExpressionFactory.Equal(instance, _sqlExpressionFactory.Constant(value)), + _sqlExpressionFactory.Constant(value.ToString(), typeof(string)))) + .ToArray(); + + return _sqlExpressionFactory.Case(cases, _sqlExpressionFactory.Constant(string.Empty, typeof(string))); + } + else if (converterType.GetGenericTypeDefinition() == typeof(EnumToStringConverter<>)) + { + // TODO: Unnecessary cast to string, #33733 + return _sqlExpressionFactory.MakeUnary(ExpressionType.Convert, instance, typeof(string)); + } + } + } + return null; } } diff --git a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs index 5dfb0bf125d..6ffd670c1ed 100644 --- a/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs +++ b/src/EFCore.Relational/Query/RelationalMethodCallTranslatorProvider.cs @@ -32,7 +32,7 @@ public RelationalMethodCallTranslatorProvider(RelationalMethodCallTranslatorProv new CollateTranslator(), new ContainsTranslator(sqlExpressionFactory), new LikeTranslator(sqlExpressionFactory), - new EnumHasFlagTranslator(sqlExpressionFactory), + new EnumMethodTranslator(sqlExpressionFactory), new GetValueOrDefaultTranslator(sqlExpressionFactory), new ComparisonTranslator(sqlExpressionFactory), new ByteArraySequenceEqualTranslator(sqlExpressionFactory), diff --git a/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerObjectToStringTranslator.cs b/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerObjectToStringTranslator.cs index 363079ca618..240d8af1997 100644 --- a/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerObjectToStringTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerObjectToStringTranslator.cs @@ -104,6 +104,8 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact _sqlExpressionFactory.Constant(true.ToString())); } + // Enums are handled by EnumMethodTranslator + return TypeMapping.TryGetValue(instance.Type, out var storeType) ? _sqlExpressionFactory.Function( "CONVERT", diff --git a/src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteObjectToStringTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteObjectToStringTranslator.cs index a8753c192b4..5e46f67bf0c 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteObjectToStringTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteObjectToStringTranslator.cs @@ -99,6 +99,8 @@ public SqliteObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory _sqlExpressionFactory.Constant(true.ToString())); } + // Enums are handled by EnumMethodTranslator + return TypeMapping.Contains(instance.Type) ? _sqlExpressionFactory.Convert(instance, typeof(string)) : null; diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryFixtureBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryFixtureBase.cs index acc1005dfd9..23688b807e7 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryFixtureBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryFixtureBase.cs @@ -339,7 +339,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con b.HasOne(w => w.Owner).WithMany(g => g.Weapons).HasForeignKey(w => w.OwnerFullName).HasPrincipalKey(g => g.FullName); }); - modelBuilder.Entity().Property(m => m.Id).ValueGeneratedNever(); + modelBuilder.Entity( + b => + { + b.Property(m => m.Id).ValueGeneratedNever(); + b.Property(m => m.Difficulty).HasConversion(); + }); modelBuilder.Entity( b => diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index 3f5a6adf305..50d9e1ee805 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -91,6 +91,34 @@ public virtual Task ToString_boolean_property_nullable(bool async) async, ss => ss.Set().Select(lh => lh.Eradicated.ToString())); + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ToString_enum_property_projection(bool async) + => AssertQuery( + async, + ss => ss.Set().Select(g => g.Rank.ToString())); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ToString_nullable_enum_property_projection(bool async) + => AssertQuery( + async, + ss => ss.Set().Select(w => w.AmmunitionType.ToString())); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ToString_enum_contains(bool async) + => AssertQuery( + async, + ss => ss.Set().Where(g => g.Difficulty.ToString().Contains("Med")).Select(g => g.CodeName)); + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual Task ToString_nullable_enum_contains(bool async) + => AssertQuery( + async, + ss => ss.Set().Where(w => w.AmmunitionType.ToString().Contains("Cart")).Select(g => g.Name)); + [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_one_to_one_and_one_to_many_self_reference(bool async) @@ -3121,16 +3149,6 @@ public virtual Task Projecting_nullable_bool_in_conditional_works(bool async) new { Prop = cg.Gear != null ? cg.Gear.HasSoulPatch : false }), e => e.Prop); - [ConditionalTheory] - [MemberData(nameof(IsAsyncData))] - public virtual Task Enum_ToString_is_client_eval(bool async) - => AssertQuery( - async, - ss => - ss.Set().OrderBy(g => g.SquadId) - .ThenBy(g => g.Nickname) - .Select(g => g.Rank.ToString())); - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_collections_naked_navigation_with_ToList(bool async) diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs index 65fa1e6b21b..391d267e46a 100644 --- a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/GearsOfWarData.cs @@ -133,7 +133,8 @@ public static IReadOnlyList CreateMissions() Timeline = new DateTimeOffset(599898024001234567, new TimeSpan(1, 30, 0)), Duration = new TimeSpan(1, 2, 3), Date = new DateOnly(2020, 1, 1), - Time = new TimeOnly(15, 30, 10) + Time = new TimeOnly(15, 30, 10), + Difficulty = MissionDifficulty.Low }, new() { @@ -143,7 +144,8 @@ public static IReadOnlyList CreateMissions() Timeline = new DateTimeOffset(2, 3, 1, 8, 0, 0, new TimeSpan(-5, 0, 0)), Duration = new TimeSpan(0, 1, 2, 3, 456), Date = new DateOnly(1990, 11, 10), - Time = new TimeOnly(10, 15, 50, 500) + Time = new TimeOnly(10, 15, 50, 500), + Difficulty = MissionDifficulty.Medium }, new() { @@ -153,7 +155,8 @@ public static IReadOnlyList CreateMissions() Timeline = new DateTimeOffset(10, 5, 3, 12, 0, 0, new TimeSpan()), Duration = new TimeSpan(0, 1, 0, 15, 456), Date = new DateOnly(1, 1, 1), - Time = new TimeOnly(0, 0, 0) + Time = new TimeOnly(0, 0, 0), + Difficulty = MissionDifficulty.Unknown } }; diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/Mission.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/Mission.cs index 930ed05a4e0..59f917d812a 100644 --- a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/Mission.cs +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/Mission.cs @@ -15,6 +15,7 @@ public class Mission public TimeSpan Duration { get; set; } public DateOnly Date { get; set; } public TimeOnly Time { get; set; } + public MissionDifficulty Difficulty { get; set; } public virtual ICollection ParticipatingSquads { get; set; } } diff --git a/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/MissionDifficulty.cs b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/MissionDifficulty.cs new file mode 100644 index 00000000000..e01ccc39e24 --- /dev/null +++ b/test/EFCore.Specification.Tests/TestModels/GearsOfWarModel/MissionDifficulty.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel; + +public enum MissionDifficulty +{ + Unknown = 0, + Low = 1, + Medium = 2, + High = 3, + Extreme = 4 +} diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 6198c915ad7..afee6372fc5 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -2697,7 +2697,7 @@ public override async Task Where_datetimeoffset_now(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] <> SYSDATETIMEOFFSET() """); @@ -2709,7 +2709,7 @@ public override async Task Where_datetimeoffset_utcnow(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] <> CAST(SYSUTCDATETIME() AS datetimeoffset) """); @@ -2723,7 +2723,7 @@ public override async Task Where_datetimeoffset_date_component(bool async) """ @__Date_0='0001-01-01T00:00:00.0000000' -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CONVERT(date, [m].[Timeline]) > @__Date_0 """); @@ -2735,7 +2735,7 @@ public override async Task Where_datetimeoffset_year_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(year, [m].[Timeline]) = 2 """); @@ -2747,7 +2747,7 @@ public override async Task Where_datetimeoffset_month_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(month, [m].[Timeline]) = 1 """); @@ -2759,7 +2759,7 @@ public override async Task Where_datetimeoffset_dayofyear_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(dayofyear, [m].[Timeline]) = 2 """); @@ -2771,7 +2771,7 @@ public override async Task Where_datetimeoffset_day_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(day, [m].[Timeline]) = 2 """); @@ -2783,7 +2783,7 @@ public override async Task Where_datetimeoffset_hour_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Timeline]) = 10 """); @@ -2795,7 +2795,7 @@ public override async Task Where_datetimeoffset_minute_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Timeline]) = 0 """); @@ -2807,7 +2807,7 @@ public override async Task Where_datetimeoffset_second_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Timeline]) = 0 """); @@ -2819,7 +2819,7 @@ public override async Task Where_datetimeoffset_millisecond_component(bool async AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Timeline]) = 0 """); @@ -2921,7 +2921,7 @@ public virtual async Task Where_AtTimeZone_datetime_constant(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] = CAST('0010-05-03T12:00:00.0000000' AS datetime2) AT TIME ZONE 'UTC' """); @@ -2950,7 +2950,7 @@ public virtual async Task Where_AtTimeZone_datetime_parameter(bool async) @__dateTime_1='0010-05-03T12:00:00.0000000' @__timeZone_2='UTC' (Size = 8000) (DbType = AnsiString) -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] = @__dateTime_1 AT TIME ZONE @__timeZone_2 """); @@ -3980,18 +3980,6 @@ FROM [Tags] AS [t] """); } - public override async Task Enum_ToString_is_client_eval(bool async) - { - await base.Enum_ToString_is_client_eval(async); - - AssertSql( - """ -SELECT [g].[Rank] -FROM [Gears] AS [g] -ORDER BY [g].[SquadId], [g].[Nickname] -"""); - } - public override async Task ToString_string_property_projection(bool async) { await base.ToString_string_property_projection(async); @@ -4032,6 +4020,71 @@ FROM [Factions] AS [f] """); } + public override async Task ToString_enum_property_projection(bool async) + { + await base.ToString_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN [g].[Rank] = 0 THEN N'None' + WHEN [g].[Rank] = 1 THEN N'Private' + WHEN [g].[Rank] = 2 THEN N'Corporal' + WHEN [g].[Rank] = 4 THEN N'Sergeant' + WHEN [g].[Rank] = 8 THEN N'Lieutenant' + WHEN [g].[Rank] = 16 THEN N'Captain' + WHEN [g].[Rank] = 32 THEN N'Major' + WHEN [g].[Rank] = 64 THEN N'Colonel' + WHEN [g].[Rank] = 128 THEN N'General' + ELSE N'' +END +FROM [Gears] AS [g] +"""); + } + + public override async Task ToString_nullable_enum_property_projection(bool async) + { + await base.ToString_nullable_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END +FROM [Weapons] AS [w] +"""); + } + + public override async Task ToString_enum_contains(bool async) + { + await base.ToString_enum_contains(async); + + AssertSql( + """ +SELECT [m].[CodeName] +FROM [Missions] AS [m] +WHERE CAST([m].[Difficulty] AS nvarchar(max)) LIKE N'%Med%' +"""); + } + + public override async Task ToString_nullable_enum_contains(bool async) + { + await base.ToString_nullable_enum_contains(async); + + AssertSql( +""" +SELECT [w].[Name] +FROM [Weapons] AS [w] +WHERE CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END LIKE N'%Cart%' +"""); + } + public override async Task Correlated_collections_naked_navigation_with_ToList(bool async) { await base.Correlated_collections_naked_navigation_with_ToList(async); @@ -6655,7 +6708,7 @@ public override async Task DateTimeOffset_Contains_Less_than_Greater_than(bool a @__end_1='1902-01-03T10:00:00.1234567+01:30' @__dates_2='["1902-01-02T10:00:00.1234567+01:30"]' (Size = 4000) -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE @__start_0 <= CAST(CONVERT(date, [m].[Timeline]) AS datetimeoffset) AND [m].[Timeline] < @__end_1 AND [m].[Timeline] IN ( SELECT [d].[value] @@ -7715,7 +7768,7 @@ public override async Task DateTimeOffset_Date_returns_datetime(bool async) """ @__dateTimeOffset_Date_0='0002-03-01T00:00:00.0000000' -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CONVERT(date, [m].[Timeline]) >= @__dateTimeOffset_Date_0 """); @@ -7875,7 +7928,7 @@ public override async Task Where_TimeSpan_Hours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Duration]) = 1 """); @@ -7887,7 +7940,7 @@ public override async Task Where_TimeSpan_Minutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Duration]) = 2 """); @@ -7899,7 +7952,7 @@ public override async Task Where_TimeSpan_Seconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Duration]) = 3 """); @@ -7911,7 +7964,7 @@ public override async Task Where_TimeSpan_Milliseconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Duration]) = 456 """); @@ -9062,7 +9115,7 @@ public override async Task Where_DateOnly_Year(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(year, [m].[Date]) = 1990 """); @@ -9074,7 +9127,7 @@ public override async Task Where_DateOnly_Month(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(month, [m].[Date]) = 11 """); @@ -9086,7 +9139,7 @@ public override async Task Where_DateOnly_Day(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(day, [m].[Date]) = 10 """); @@ -9098,7 +9151,7 @@ public override async Task Where_DateOnly_DayOfYear(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(dayofyear, [m].[Date]) = 314 """); @@ -9117,7 +9170,7 @@ public override async Task Where_DateOnly_AddYears(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(year, CAST(3 AS int), [m].[Date]) = '1993-11-10' """); @@ -9129,7 +9182,7 @@ public override async Task Where_DateOnly_AddMonths(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(month, CAST(3 AS int), [m].[Date]) = '1991-02-10' """); @@ -9141,7 +9194,7 @@ public override async Task Where_DateOnly_AddDays(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(day, CAST(3 AS int), [m].[Date]) = '1990-11-13' """); @@ -9153,7 +9206,7 @@ public override async Task Where_TimeOnly_Hour(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Time]) = 10 """); @@ -9165,7 +9218,7 @@ public override async Task Where_TimeOnly_Minute(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Time]) = 15 """); @@ -9177,7 +9230,7 @@ public override async Task Where_TimeOnly_Second(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Time]) = 50 """); @@ -9189,7 +9242,7 @@ public override async Task Where_TimeOnly_Millisecond(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Time]) = 500 """); @@ -9201,7 +9254,7 @@ public override async Task Where_TimeOnly_AddHours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(hour, CAST(3.0E0 AS int), [m].[Time]) = '13:15:50.5' """); @@ -9213,7 +9266,7 @@ public override async Task Where_TimeOnly_AddMinutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(minute, CAST(3.0E0 AS int), [m].[Time]) = '10:18:50.5' """); @@ -9232,7 +9285,7 @@ public override async Task Where_TimeOnly_IsBetween(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CASE WHEN [m].[Time] >= '10:00:00' THEN CAST(1 AS bit) @@ -9297,7 +9350,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_property(bool AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CAST([m].[Duration] AS time) < [m].[Time] """); @@ -9311,7 +9364,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_parameter(boo """ @__time_0='01:02' (DbType = Time) -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CAST([m].[Duration] AS time) = @__time_0 """); @@ -9323,7 +9376,7 @@ public override async Task Order_by_TimeOnly_FromTimeSpan(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] ORDER BY CAST([m].[Duration] AS time) """); @@ -9628,7 +9681,7 @@ public override async Task Where_equals_method_on_nullable_with_object_overload( AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Rating] IS NULL """); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs index fa76dc4a5c6..061253aefa9 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs @@ -3780,7 +3780,7 @@ public override async Task Where_datetimeoffset_now(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] <> SYSDATETIMEOFFSET() """); @@ -3792,7 +3792,7 @@ public override async Task Where_datetimeoffset_utcnow(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] <> CAST(SYSUTCDATETIME() AS datetimeoffset) """); @@ -3806,7 +3806,7 @@ public override async Task Where_datetimeoffset_date_component(bool async) """ @__Date_0='0001-01-01T00:00:00.0000000' -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CONVERT(date, [m].[Timeline]) > @__Date_0 """); @@ -3818,7 +3818,7 @@ public override async Task Where_datetimeoffset_year_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(year, [m].[Timeline]) = 2 """); @@ -3830,7 +3830,7 @@ public override async Task Where_datetimeoffset_month_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(month, [m].[Timeline]) = 1 """); @@ -3842,7 +3842,7 @@ public override async Task Where_datetimeoffset_dayofyear_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(dayofyear, [m].[Timeline]) = 2 """); @@ -3854,7 +3854,7 @@ public override async Task Where_datetimeoffset_day_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(day, [m].[Timeline]) = 2 """); @@ -3866,7 +3866,7 @@ public override async Task Where_datetimeoffset_hour_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Timeline]) = 10 """); @@ -3878,7 +3878,7 @@ public override async Task Where_datetimeoffset_minute_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Timeline]) = 0 """); @@ -3890,7 +3890,7 @@ public override async Task Where_datetimeoffset_second_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Timeline]) = 0 """); @@ -3902,7 +3902,7 @@ public override async Task Where_datetimeoffset_millisecond_component(bool async AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Timeline]) = 0 """); @@ -5383,21 +5383,74 @@ FROM [Officers] AS [o] """); } - public override async Task Enum_ToString_is_client_eval(bool async) + public override async Task ToString_enum_property_projection(bool async) { - await base.Enum_ToString_is_client_eval(async); + await base.ToString_enum_property_projection(async); AssertSql( - """ -SELECT [u].[Rank] +""" +SELECT CASE + WHEN [u].[Rank] = 0 THEN N'None' + WHEN [u].[Rank] = 1 THEN N'Private' + WHEN [u].[Rank] = 2 THEN N'Corporal' + WHEN [u].[Rank] = 4 THEN N'Sergeant' + WHEN [u].[Rank] = 8 THEN N'Lieutenant' + WHEN [u].[Rank] = 16 THEN N'Captain' + WHEN [u].[Rank] = 32 THEN N'Major' + WHEN [u].[Rank] = 64 THEN N'Colonel' + WHEN [u].[Rank] = 128 THEN N'General' + ELSE N'' +END FROM ( - SELECT [g].[Nickname], [g].[SquadId], [g].[Rank] + SELECT [g].[Rank] FROM [Gears] AS [g] UNION ALL - SELECT [o].[Nickname], [o].[SquadId], [o].[Rank] + SELECT [o].[Rank] FROM [Officers] AS [o] ) AS [u] -ORDER BY [u].[SquadId], [u].[Nickname] +"""); + } + + public override async Task ToString_nullable_enum_property_projection(bool async) + { + await base.ToString_nullable_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END +FROM [Weapons] AS [w] +"""); + } + + public override async Task ToString_enum_contains(bool async) + { + await base.ToString_enum_contains(async); + + AssertSql( +""" +SELECT [m].[CodeName] +FROM [Missions] AS [m] +WHERE CAST([m].[Difficulty] AS nvarchar(max)) LIKE N'%Med%' +"""); + } + + public override async Task ToString_nullable_enum_contains(bool async) + { + await base.ToString_nullable_enum_contains(async); + + AssertSql( +""" +SELECT [w].[Name] +FROM [Weapons] AS [w] +WHERE CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END LIKE N'%Cart%' """); } @@ -8957,7 +9010,7 @@ public override async Task DateTimeOffset_Contains_Less_than_Greater_than(bool a @__end_1='1902-01-03T10:00:00.1234567+01:30' @__dates_2='["1902-01-02T10:00:00.1234567+01:30"]' (Size = 4000) -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE @__start_0 <= CAST(CONVERT(date, [m].[Timeline]) AS datetimeoffset) AND [m].[Timeline] < @__end_1 AND [m].[Timeline] IN ( SELECT [d].[value] @@ -10272,7 +10325,7 @@ public override async Task DateTimeOffset_Date_returns_datetime(bool async) """ @__dateTimeOffset_Date_0='0002-03-01T00:00:00.0000000' -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CONVERT(date, [m].[Timeline]) >= @__dateTimeOffset_Date_0 """); @@ -10462,7 +10515,7 @@ public override async Task Where_TimeSpan_Hours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Duration]) = 1 """); @@ -10474,7 +10527,7 @@ public override async Task Where_TimeSpan_Minutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Duration]) = 2 """); @@ -10486,7 +10539,7 @@ public override async Task Where_TimeSpan_Seconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Duration]) = 3 """); @@ -10498,7 +10551,7 @@ public override async Task Where_TimeSpan_Milliseconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Duration]) = 456 """); @@ -11663,7 +11716,7 @@ public override async Task Where_DateOnly_Year(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(year, [m].[Date]) = 1990 """); @@ -11675,7 +11728,7 @@ public override async Task Where_DateOnly_Month(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(month, [m].[Date]) = 11 """); @@ -11687,7 +11740,7 @@ public override async Task Where_DateOnly_Day(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(day, [m].[Date]) = 10 """); @@ -11699,7 +11752,7 @@ public override async Task Where_DateOnly_DayOfYear(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(dayofyear, [m].[Date]) = 314 """); @@ -11718,7 +11771,7 @@ public override async Task Where_DateOnly_AddYears(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(year, CAST(3 AS int), [m].[Date]) = '1993-11-10' """); @@ -11730,7 +11783,7 @@ public override async Task Where_DateOnly_AddMonths(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(month, CAST(3 AS int), [m].[Date]) = '1991-02-10' """); @@ -11742,7 +11795,7 @@ public override async Task Where_DateOnly_AddDays(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(day, CAST(3 AS int), [m].[Date]) = '1990-11-13' """); @@ -11754,7 +11807,7 @@ public override async Task Where_TimeOnly_Hour(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Time]) = 10 """); @@ -11766,7 +11819,7 @@ public override async Task Where_TimeOnly_Minute(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Time]) = 15 """); @@ -11778,7 +11831,7 @@ public override async Task Where_TimeOnly_Second(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Time]) = 50 """); @@ -11790,7 +11843,7 @@ public override async Task Where_TimeOnly_Millisecond(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Time]) = 500 """); @@ -11802,7 +11855,7 @@ public override async Task Where_TimeOnly_AddHours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(hour, CAST(3.0E0 AS int), [m].[Time]) = '13:15:50.5' """); @@ -11814,7 +11867,7 @@ public override async Task Where_TimeOnly_AddMinutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(minute, CAST(3.0E0 AS int), [m].[Time]) = '10:18:50.5' """); @@ -11833,7 +11886,7 @@ public override async Task Where_TimeOnly_IsBetween(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CASE WHEN [m].[Time] >= '10:00:00' THEN CAST(1 AS bit) @@ -11904,7 +11957,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_property(bool AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CAST([m].[Duration] AS time) < [m].[Time] """); @@ -11918,7 +11971,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_parameter(boo """ @__time_0='01:02' (DbType = Time) -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CAST([m].[Duration] AS time) = @__time_0 """); @@ -11930,7 +11983,7 @@ public override async Task Order_by_TimeOnly_FromTimeSpan(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] ORDER BY CAST([m].[Duration] AS time) """); @@ -12513,7 +12566,7 @@ public override async Task Where_equals_method_on_nullable_with_object_overload( AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Rating] IS NULL """); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs index 6df09080b56..30db3787120 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs @@ -3193,7 +3193,7 @@ public override async Task Where_datetimeoffset_now(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] <> SYSDATETIMEOFFSET() """); @@ -3205,7 +3205,7 @@ public override async Task Where_datetimeoffset_utcnow(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Timeline] <> CAST(SYSUTCDATETIME() AS datetimeoffset) """); @@ -3219,7 +3219,7 @@ public override async Task Where_datetimeoffset_date_component(bool async) """ @__Date_0='0001-01-01T00:00:00.0000000' -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CONVERT(date, [m].[Timeline]) > @__Date_0 """); @@ -3231,7 +3231,7 @@ public override async Task Where_datetimeoffset_year_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(year, [m].[Timeline]) = 2 """); @@ -3243,7 +3243,7 @@ public override async Task Where_datetimeoffset_month_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(month, [m].[Timeline]) = 1 """); @@ -3255,7 +3255,7 @@ public override async Task Where_datetimeoffset_dayofyear_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(dayofyear, [m].[Timeline]) = 2 """); @@ -3267,7 +3267,7 @@ public override async Task Where_datetimeoffset_day_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(day, [m].[Timeline]) = 2 """); @@ -3279,7 +3279,7 @@ public override async Task Where_datetimeoffset_hour_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Timeline]) = 10 """); @@ -3291,7 +3291,7 @@ public override async Task Where_datetimeoffset_minute_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Timeline]) = 0 """); @@ -3303,7 +3303,7 @@ public override async Task Where_datetimeoffset_second_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Timeline]) = 0 """); @@ -3315,7 +3315,7 @@ public override async Task Where_datetimeoffset_millisecond_component(bool async AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Timeline]) = 0 """); @@ -4669,15 +4669,68 @@ FROM [Gears] AS [g] """); } - public override async Task Enum_ToString_is_client_eval(bool async) + public override async Task ToString_enum_property_projection(bool async) { - await base.Enum_ToString_is_client_eval(async); + await base.ToString_enum_property_projection(async); AssertSql( - """ -SELECT [g].[Rank] +""" +SELECT CASE + WHEN [g].[Rank] = 0 THEN N'None' + WHEN [g].[Rank] = 1 THEN N'Private' + WHEN [g].[Rank] = 2 THEN N'Corporal' + WHEN [g].[Rank] = 4 THEN N'Sergeant' + WHEN [g].[Rank] = 8 THEN N'Lieutenant' + WHEN [g].[Rank] = 16 THEN N'Captain' + WHEN [g].[Rank] = 32 THEN N'Major' + WHEN [g].[Rank] = 64 THEN N'Colonel' + WHEN [g].[Rank] = 128 THEN N'General' + ELSE N'' +END FROM [Gears] AS [g] -ORDER BY [g].[SquadId], [g].[Nickname] +"""); + } + + public override async Task ToString_nullable_enum_property_projection(bool async) + { + await base.ToString_nullable_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END +FROM [Weapons] AS [w] +"""); + } + + public override async Task ToString_enum_contains(bool async) + { + await base.ToString_enum_contains(async); + + AssertSql( + """ +SELECT [m].[CodeName] +FROM [Missions] AS [m] +WHERE CAST([m].[Difficulty] AS nvarchar(max)) LIKE N'%Med%' +"""); + } + + public override async Task ToString_nullable_enum_contains(bool async) + { + await base.ToString_nullable_enum_contains(async); + + AssertSql( +""" +SELECT [w].[Name] +FROM [Weapons] AS [w] +WHERE CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END LIKE N'%Cart%' """); } @@ -7559,7 +7612,7 @@ public override async Task DateTimeOffset_Contains_Less_than_Greater_than(bool a @__end_1='1902-01-03T10:00:00.1234567+01:30' @__dates_2='["1902-01-02T10:00:00.1234567+01:30"]' (Size = 4000) -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE @__start_0 <= CAST(CONVERT(date, [m].[Timeline]) AS datetimeoffset) AND [m].[Timeline] < @__end_1 AND [m].[Timeline] IN ( SELECT [d].[value] @@ -8743,7 +8796,7 @@ public override async Task DateTimeOffset_Date_returns_datetime(bool async) """ @__dateTimeOffset_Date_0='0002-03-01T00:00:00.0000000' -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CONVERT(date, [m].[Timeline]) >= @__dateTimeOffset_Date_0 """); @@ -8909,7 +8962,7 @@ public override async Task Where_TimeSpan_Hours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Duration]) = 1 """); @@ -8921,7 +8974,7 @@ public override async Task Where_TimeSpan_Minutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Duration]) = 2 """); @@ -8933,7 +8986,7 @@ public override async Task Where_TimeSpan_Seconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Duration]) = 3 """); @@ -8945,7 +8998,7 @@ public override async Task Where_TimeSpan_Milliseconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Duration]) = 456 """); @@ -9890,7 +9943,7 @@ public override async Task Where_DateOnly_Year(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(year, [m].[Date]) = 1990 """); @@ -9902,7 +9955,7 @@ public override async Task Where_DateOnly_Month(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(month, [m].[Date]) = 11 """); @@ -9914,7 +9967,7 @@ public override async Task Where_DateOnly_Day(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(day, [m].[Date]) = 10 """); @@ -9926,7 +9979,7 @@ public override async Task Where_DateOnly_DayOfYear(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(dayofyear, [m].[Date]) = 314 """); @@ -9945,7 +9998,7 @@ public override async Task Where_DateOnly_AddYears(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(year, CAST(3 AS int), [m].[Date]) = '1993-11-10' """); @@ -9957,7 +10010,7 @@ public override async Task Where_DateOnly_AddMonths(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(month, CAST(3 AS int), [m].[Date]) = '1991-02-10' """); @@ -9969,7 +10022,7 @@ public override async Task Where_DateOnly_AddDays(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(day, CAST(3 AS int), [m].[Date]) = '1990-11-13' """); @@ -9981,7 +10034,7 @@ public override async Task Where_TimeOnly_Hour(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(hour, [m].[Time]) = 10 """); @@ -9993,7 +10046,7 @@ public override async Task Where_TimeOnly_Minute(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(minute, [m].[Time]) = 15 """); @@ -10005,7 +10058,7 @@ public override async Task Where_TimeOnly_Second(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(second, [m].[Time]) = 50 """); @@ -10017,7 +10070,7 @@ public override async Task Where_TimeOnly_Millisecond(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEPART(millisecond, [m].[Time]) = 500 """); @@ -10029,7 +10082,7 @@ public override async Task Where_TimeOnly_AddHours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(hour, CAST(3.0E0 AS int), [m].[Time]) = '13:15:50.5' """); @@ -10041,7 +10094,7 @@ public override async Task Where_TimeOnly_AddMinutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE DATEADD(minute, CAST(3.0E0 AS int), [m].[Time]) = '10:18:50.5' """); @@ -10060,7 +10113,7 @@ public override async Task Where_TimeOnly_IsBetween(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CASE WHEN [m].[Time] >= '10:00:00' THEN CAST(1 AS bit) @@ -10128,7 +10181,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_property(bool AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CAST([m].[Duration] AS time) < [m].[Time] """); @@ -10142,7 +10195,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_parameter(boo """ @__time_0='01:02' (DbType = Time) -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE CAST([m].[Duration] AS time) = @__time_0 """); @@ -10154,7 +10207,7 @@ public override async Task Order_by_TimeOnly_FromTimeSpan(bool async) AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] ORDER BY CAST([m].[Duration] AS time) """); @@ -10691,7 +10744,7 @@ public override async Task Where_equals_method_on_nullable_with_object_overload( AssertSql( """ -SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] WHERE [m].[Rating] IS NULL """); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs index 4804b9024ed..f927d763281 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TemporalGearsOfWarQuerySqlServerTest.cs @@ -242,7 +242,7 @@ public override async Task Where_DateOnly_Year(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(year, [m].[Date]) = 1990 """); @@ -254,7 +254,7 @@ public override async Task Where_DateOnly_Month(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(month, [m].[Date]) = 11 """); @@ -266,7 +266,7 @@ public override async Task Where_DateOnly_Day(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(day, [m].[Date]) = 10 """); @@ -278,7 +278,7 @@ public override async Task Where_DateOnly_DayOfYear(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(dayofyear, [m].[Date]) = 314 """); @@ -297,7 +297,7 @@ public override async Task Where_DateOnly_AddYears(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEADD(year, CAST(3 AS int), [m].[Date]) = '1993-11-10' """); @@ -309,7 +309,7 @@ public override async Task Where_DateOnly_AddMonths(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEADD(month, CAST(3 AS int), [m].[Date]) = '1991-02-10' """); @@ -321,7 +321,7 @@ public override async Task Where_DateOnly_AddDays(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEADD(day, CAST(3 AS int), [m].[Date]) = '1990-11-13' """); @@ -333,7 +333,7 @@ public override async Task Where_TimeOnly_Hour(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(hour, [m].[Time]) = 10 """); @@ -345,7 +345,7 @@ public override async Task Where_TimeOnly_Minute(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(minute, [m].[Time]) = 15 """); @@ -357,7 +357,7 @@ public override async Task Where_TimeOnly_Second(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(second, [m].[Time]) = 50 """); @@ -369,7 +369,7 @@ public override async Task Where_TimeOnly_Millisecond(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(millisecond, [m].[Time]) = 500 """); @@ -381,7 +381,7 @@ public override async Task Where_TimeOnly_AddHours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEADD(hour, CAST(3.0E0 AS int), [m].[Time]) = '13:15:50.5' """); @@ -393,7 +393,7 @@ public override async Task Where_TimeOnly_AddMinutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEADD(minute, CAST(3.0E0 AS int), [m].[Time]) = '10:18:50.5' """); @@ -412,7 +412,7 @@ public override async Task Where_TimeOnly_IsBetween(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE CASE WHEN [m].[Time] >= '10:00:00' THEN CAST(1 AS bit) @@ -477,7 +477,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_property(bool AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE CAST([m].[Duration] AS time) < [m].[Time] """); @@ -491,7 +491,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_parameter(boo """ @__time_0='01:02' (DbType = Time) -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE CAST([m].[Duration] AS time) = @__time_0 """); @@ -503,7 +503,7 @@ public override async Task Order_by_TimeOnly_FromTimeSpan(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] ORDER BY CAST([m].[Duration] AS time) """); @@ -897,7 +897,7 @@ public override async Task Where_datetimeoffset_month_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(month, [m].[Timeline]) = 1 """); @@ -1208,7 +1208,7 @@ public override async Task Where_datetimeoffset_minute_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(minute, [m].[Timeline]) = 0 """); @@ -2250,7 +2250,7 @@ public override async Task Where_datetimeoffset_second_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(second, [m].[Timeline]) = 0 """); @@ -2928,7 +2928,7 @@ public override async Task Where_TimeSpan_Seconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(second, [m].[Duration]) = 3 """); @@ -3030,7 +3030,7 @@ public override async Task Where_datetimeoffset_millisecond_component(bool async AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(millisecond, [m].[Timeline]) = 0 """); @@ -3503,7 +3503,7 @@ public override async Task Where_TimeSpan_Hours(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(hour, [m].[Duration]) = 1 """); @@ -4124,7 +4124,7 @@ public override async Task Where_datetimeoffset_utcnow(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE [m].[Timeline] <> CAST(SYSUTCDATETIME() AS datetimeoffset) """); @@ -4207,7 +4207,7 @@ public override async Task Where_datetimeoffset_now(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE [m].[Timeline] <> SYSDATETIMEOFFSET() """); @@ -4394,18 +4394,6 @@ LEFT JOIN ( """); } - public override async Task Enum_ToString_is_client_eval(bool async) - { - await base.Enum_ToString_is_client_eval(async); - - AssertSql( - """ -SELECT [g].[Rank] -FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g] -ORDER BY [g].[SquadId], [g].[Nickname] -"""); - } - public override async Task Include_with_nested_navigation_in_order_by(bool async) { await base.Include_with_nested_navigation_in_order_by(async); @@ -4519,7 +4507,7 @@ public override async Task Where_datetimeoffset_dayofyear_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(dayofyear, [m].[Timeline]) = 2 """); @@ -4808,6 +4796,71 @@ public override async Task Where_enum_has_flag(bool async) """); } + public override async Task ToString_enum_property_projection(bool async) + { + await base.ToString_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN [g].[Rank] = 0 THEN N'None' + WHEN [g].[Rank] = 1 THEN N'Private' + WHEN [g].[Rank] = 2 THEN N'Corporal' + WHEN [g].[Rank] = 4 THEN N'Sergeant' + WHEN [g].[Rank] = 8 THEN N'Lieutenant' + WHEN [g].[Rank] = 16 THEN N'Captain' + WHEN [g].[Rank] = 32 THEN N'Major' + WHEN [g].[Rank] = 64 THEN N'Colonel' + WHEN [g].[Rank] = 128 THEN N'General' + ELSE N'' +END +FROM [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g] +"""); + } + + public override async Task ToString_nullable_enum_property_projection(bool async) + { + await base.ToString_nullable_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END +FROM [Weapons] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [w] +"""); + } + + public override async Task ToString_enum_contains(bool async) + { + await base.ToString_enum_contains(async); + + AssertSql( +""" +SELECT [m].[CodeName] +FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] +WHERE CAST([m].[Difficulty] AS nvarchar(max)) LIKE N'%Med%' +"""); + } + + public override async Task ToString_nullable_enum_contains(bool async) + { + await base.ToString_nullable_enum_contains(async); + + AssertSql( +""" +SELECT [w].[Name] +FROM [Weapons] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [w] +WHERE CASE + WHEN [w].[AmmunitionType] = 1 THEN N'Cartridge' + WHEN [w].[AmmunitionType] = 2 THEN N'Shell' + ELSE N'' +END LIKE N'%Cart%' +"""); + } + public override async Task Correlated_collections_naked_navigation_with_ToList(bool async) { await base.Correlated_collections_naked_navigation_with_ToList(async); @@ -5708,7 +5761,7 @@ public override async Task Where_TimeSpan_Milliseconds(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(millisecond, [m].[Duration]) = 456 """); @@ -6240,7 +6293,7 @@ public override async Task Where_datetimeoffset_date_component(bool async) """ @__Date_0='0001-01-01T00:00:00.0000000' -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE CONVERT(date, [m].[Timeline]) > @__Date_0 """); @@ -6375,7 +6428,7 @@ public override async Task DateTimeOffset_Contains_Less_than_Greater_than(bool a @__end_1='1902-01-03T10:00:00.1234567+01:30' @__dates_2='["1902-01-02T10:00:00.1234567+01:30"]' (Size = 4000) -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE @__start_0 <= CAST(CONVERT(date, [m].[Timeline]) AS datetimeoffset) AND [m].[Timeline] < @__end_1 AND [m].[Timeline] IN ( SELECT [d].[value] @@ -6670,7 +6723,7 @@ public override async Task Where_datetimeoffset_year_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(year, [m].[Timeline]) = 2 """); @@ -6795,7 +6848,7 @@ public override async Task Where_datetimeoffset_day_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(day, [m].[Timeline]) = 2 """); @@ -6913,7 +6966,7 @@ public override async Task Where_datetimeoffset_hour_component(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(hour, [m].[Timeline]) = 10 """); @@ -8701,7 +8754,7 @@ public override async Task Where_TimeSpan_Minutes(bool async) AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE DATEPART(minute, [m].[Duration]) = 2 """); @@ -9095,7 +9148,7 @@ public override async Task Where_equals_method_on_nullable_with_object_overload( AssertSql( """ -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE [m].[Rating] IS NULL """); @@ -9517,7 +9570,7 @@ public override async Task DateTimeOffset_Date_returns_datetime(bool async) """ @__dateTimeOffset_Date_0='0002-03-01T00:00:00.0000000' -SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] +SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[PeriodEnd], [m].[PeriodStart], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [m] WHERE CONVERT(date, [m].[Timeline]) >= @__dateTimeOffset_Date_0 """); diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs index 0ff7f0f8cf9..42e2ed0a4bd 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/GearsOfWarQuerySqliteTest.cs @@ -504,7 +504,7 @@ public override async Task Where_DateOnly_Year(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE CAST(strftime('%Y', "m"."Date") AS INTEGER) = 1990 """); @@ -516,7 +516,7 @@ public override async Task Where_DateOnly_Month(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE CAST(strftime('%m', "m"."Date") AS INTEGER) = 11 """); @@ -528,7 +528,7 @@ public override async Task Where_DateOnly_Day(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE CAST(strftime('%d', "m"."Date") AS INTEGER) = 10 """); @@ -540,7 +540,7 @@ public override async Task Where_DateOnly_DayOfYear(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE CAST(strftime('%j', "m"."Date") AS INTEGER) = 314 """); @@ -552,7 +552,7 @@ public override async Task Where_DateOnly_DayOfWeek(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE CAST(strftime('%w', "m"."Date") AS INTEGER) = 6 """); @@ -564,7 +564,7 @@ public override async Task Where_DateOnly_AddYears(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE date("m"."Date", CAST(3 AS TEXT) || ' years') = '1993-11-10' """); @@ -580,7 +580,7 @@ await AssertQuery( AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE CAST(strftime('%Y', "m"."Date", CAST(3 AS TEXT) || ' years') AS INTEGER) = 1993 """); @@ -596,7 +596,7 @@ await AssertQuery( AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE date("m"."Date", CAST(3 AS TEXT) || ' years', CAST(3 AS TEXT) || ' months') = '1994-02-10' """); @@ -608,7 +608,7 @@ public override async Task Where_DateOnly_AddMonths(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE date("m"."Date", CAST(3 AS TEXT) || ' months') = '1991-02-10' """); @@ -620,7 +620,7 @@ public override async Task Where_DateOnly_AddDays(bool async) AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE date("m"."Date", CAST(3 AS TEXT) || ' days') = '1990-11-13' """); @@ -2361,18 +2361,6 @@ public override async Task Join_on_entity_qsre_keys_outer_key_is_navigation(bool """); } - public override async Task Enum_ToString_is_client_eval(bool async) - { - await base.Enum_ToString_is_client_eval(async); - - AssertSql( - """ -SELECT "g"."Rank" -FROM "Gears" AS "g" -ORDER BY "g"."SquadId", "g"."Nickname" -"""); - } - public override async Task Include_with_join_collection2(bool async) { await base.Include_with_join_collection2(async); @@ -3447,6 +3435,71 @@ public override async Task Correlated_collections_project_anonymous_collection_r """); } + public override async Task ToString_enum_property_projection(bool async) + { + await base.ToString_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN "g"."Rank" = 0 THEN 'None' + WHEN "g"."Rank" = 1 THEN 'Private' + WHEN "g"."Rank" = 2 THEN 'Corporal' + WHEN "g"."Rank" = 4 THEN 'Sergeant' + WHEN "g"."Rank" = 8 THEN 'Lieutenant' + WHEN "g"."Rank" = 16 THEN 'Captain' + WHEN "g"."Rank" = 32 THEN 'Major' + WHEN "g"."Rank" = 64 THEN 'Colonel' + WHEN "g"."Rank" = 128 THEN 'General' + ELSE '' +END +FROM "Gears" AS "g" +"""); + } + + public override async Task ToString_nullable_enum_property_projection(bool async) + { + await base.ToString_nullable_enum_property_projection(async); + + AssertSql( +""" +SELECT CASE + WHEN "w"."AmmunitionType" = 1 THEN 'Cartridge' + WHEN "w"."AmmunitionType" = 2 THEN 'Shell' + ELSE '' +END +FROM "Weapons" AS "w" +"""); + } + + public override async Task ToString_enum_contains(bool async) + { + await base.ToString_enum_contains(async); + + AssertSql( +""" +SELECT "m"."CodeName" +FROM "Missions" AS "m" +WHERE instr(CAST("m"."Difficulty" AS TEXT), 'Med') > 0 +"""); + } + + public override async Task ToString_nullable_enum_contains(bool async) + { + await base.ToString_nullable_enum_contains(async); + + AssertSql( +""" +SELECT "w"."Name" +FROM "Weapons" AS "w" +WHERE instr(CASE + WHEN "w"."AmmunitionType" = 1 THEN 'Cartridge' + WHEN "w"."AmmunitionType" = 2 THEN 'Shell' + ELSE '' +END, 'Cart') > 0 +"""); + } + public override async Task Correlated_collections_naked_navigation_with_ToList(bool async) { await base.Correlated_collections_naked_navigation_with_ToList(async); @@ -6571,7 +6624,7 @@ public override async Task Where_equals_method_on_nullable_with_object_overload( AssertSql( """ -SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" +SELECT "m"."Id", "m"."CodeName", "m"."Date", "m"."Difficulty", "m"."Duration", "m"."Rating", "m"."Time", "m"."Timeline" FROM "Missions" AS "m" WHERE "m"."Rating" IS NULL """);