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 57% rename from src/EFCore.Relational/Query/Internal/Translators/EnumHasFlagTranslator.cs rename to src/EFCore.Relational/Query/Internal/Translators/EnumMethodTranslator.cs index dbf6db241f2..d1cdfd4b487 100644 --- a/src/EFCore.Relational/Query/Internal/Translators/EnumHasFlagTranslator.cs +++ b/src/EFCore.Relational/Query/Internal/Translators/EnumMethodTranslator.cs @@ -12,11 +12,14 @@ 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 + private static readonly MethodInfo HasFlagMethodInfo = typeof(Enum).GetRuntimeMethod(nameof(Enum.HasFlag), [typeof(Enum)])!; + private static readonly MethodInfo ToStringMethodInfo + = typeof(object).GetRuntimeMethod(nameof(ToString), [])!; + 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,35 @@ public EnumHasFlagTranslator(ISqlExpressionFactory sqlExpressionFactory) : _sqlExpressionFactory.Equal(_sqlExpressionFactory.And(instance, argument), argument); } + if (Equals(method, ToStringMethodInfo) + && instance is { Type.IsEnum: true, TypeMapping.Converter: ValueConverter converter } + && converter.GetType() is { IsGenericType: true } converterType) + { + switch (converterType) + { + case not null when converterType.GetGenericTypeDefinition() == typeof(EnumToNumberConverter<,>): + var whenClauses = Enum.GetValues(instance.Type) + .Cast() + .Select(value => new CaseWhenClause( + _sqlExpressionFactory.Constant(value), + _sqlExpressionFactory.Constant(value.ToString(), typeof(string)))) + .ToArray(); + + var elseResult = _sqlExpressionFactory.Coalesce( + _sqlExpressionFactory.Convert(instance, typeof(string)), + _sqlExpressionFactory.Constant(string.Empty)); + + return _sqlExpressionFactory.Case(instance, whenClauses, elseResult); + + case not null when converterType.GetGenericTypeDefinition() == typeof(EnumToStringConverter<>): + // TODO: Unnecessary cast to string, #33733 + return _sqlExpressionFactory.Convert(instance, typeof(string)); + + default: + return null; + } + } + 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 2cc24ac5c8c..27b56b0b855 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -2694,7 +2694,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() """); @@ -2706,7 +2706,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) """); @@ -2720,7 +2720,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 """); @@ -2732,7 +2732,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 """); @@ -2744,7 +2744,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 """); @@ -2756,7 +2756,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 """); @@ -2768,7 +2768,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 """); @@ -2780,7 +2780,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 """); @@ -2792,7 +2792,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 """); @@ -2804,7 +2804,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 """); @@ -2816,7 +2816,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 """); @@ -2918,7 +2918,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' """); @@ -2947,7 +2947,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 """); @@ -3977,18 +3977,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); @@ -4029,6 +4017,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 [g].[Rank] + WHEN 0 THEN N'None' + WHEN 1 THEN N'Private' + WHEN 2 THEN N'Corporal' + WHEN 4 THEN N'Sergeant' + WHEN 8 THEN N'Lieutenant' + WHEN 16 THEN N'Captain' + WHEN 32 THEN N'Major' + WHEN 64 THEN N'Colonel' + WHEN 128 THEN N'General' + ELSE COALESCE(CAST([g].[Rank] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), 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); @@ -6652,7 +6705,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] @@ -7712,7 +7765,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 """); @@ -7872,7 +7925,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 """); @@ -7884,7 +7937,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 """); @@ -7896,7 +7949,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 """); @@ -7908,7 +7961,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 """); @@ -9059,7 +9112,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 """); @@ -9071,7 +9124,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 """); @@ -9083,7 +9136,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 """); @@ -9095,7 +9148,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 """); @@ -9114,7 +9167,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' """); @@ -9126,7 +9179,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' """); @@ -9138,7 +9191,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' """); @@ -9150,7 +9203,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 """); @@ -9162,7 +9215,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 """); @@ -9174,7 +9227,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 """); @@ -9186,7 +9239,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 """); @@ -9198,7 +9251,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' """); @@ -9210,7 +9263,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' """); @@ -9229,7 +9282,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) @@ -9294,7 +9347,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] """); @@ -9308,7 +9361,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 """); @@ -9320,7 +9373,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) """); @@ -9625,7 +9678,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 e8e339ef27f..2d0446b499d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPCGearsOfWarQuerySqlServerTest.cs @@ -3777,7 +3777,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() """); @@ -3789,7 +3789,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) """); @@ -3803,7 +3803,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 """); @@ -3815,7 +3815,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 """); @@ -3827,7 +3827,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 """); @@ -3839,7 +3839,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 """); @@ -3851,7 +3851,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 """); @@ -3863,7 +3863,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 """); @@ -3875,7 +3875,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 """); @@ -3887,7 +3887,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 """); @@ -3899,7 +3899,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 """); @@ -5380,21 +5380,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 [u].[Rank] + WHEN 0 THEN N'None' + WHEN 1 THEN N'Private' + WHEN 2 THEN N'Corporal' + WHEN 4 THEN N'Sergeant' + WHEN 8 THEN N'Lieutenant' + WHEN 16 THEN N'Captain' + WHEN 32 THEN N'Major' + WHEN 64 THEN N'Colonel' + WHEN 128 THEN N'General' + ELSE COALESCE(CAST([u].[Rank] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), N'') +END LIKE N'%Cart%' """); } @@ -8954,7 +9007,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] @@ -10269,7 +10322,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 """); @@ -10459,7 +10512,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 """); @@ -10471,7 +10524,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 """); @@ -10483,7 +10536,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 """); @@ -10495,7 +10548,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 """); @@ -11660,7 +11713,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 """); @@ -11672,7 +11725,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 """); @@ -11684,7 +11737,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 """); @@ -11696,7 +11749,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 """); @@ -11715,7 +11768,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' """); @@ -11727,7 +11780,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' """); @@ -11739,7 +11792,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' """); @@ -11751,7 +11804,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 """); @@ -11763,7 +11816,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 """); @@ -11775,7 +11828,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 """); @@ -11787,7 +11840,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 """); @@ -11799,7 +11852,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' """); @@ -11811,7 +11864,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' """); @@ -11830,7 +11883,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) @@ -11901,7 +11954,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] """); @@ -11915,7 +11968,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 """); @@ -11927,7 +11980,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) """); @@ -12510,7 +12563,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 01391120231..3fac2c5e7a2 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/TPTGearsOfWarQuerySqlServerTest.cs @@ -3190,7 +3190,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() """); @@ -3202,7 +3202,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) """); @@ -3216,7 +3216,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 """); @@ -3228,7 +3228,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 """); @@ -3240,7 +3240,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 """); @@ -3252,7 +3252,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 """); @@ -3264,7 +3264,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 """); @@ -3276,7 +3276,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 """); @@ -3288,7 +3288,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 """); @@ -3300,7 +3300,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 """); @@ -3312,7 +3312,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 """); @@ -4666,15 +4666,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 [g].[Rank] + WHEN 0 THEN N'None' + WHEN 1 THEN N'Private' + WHEN 2 THEN N'Corporal' + WHEN 4 THEN N'Sergeant' + WHEN 8 THEN N'Lieutenant' + WHEN 16 THEN N'Captain' + WHEN 32 THEN N'Major' + WHEN 64 THEN N'Colonel' + WHEN 128 THEN N'General' + ELSE COALESCE(CAST([g].[Rank] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), N'') +END LIKE N'%Cart%' """); } @@ -7556,7 +7609,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] @@ -8740,7 +8793,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 """); @@ -8906,7 +8959,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 """); @@ -8918,7 +8971,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 """); @@ -8930,7 +8983,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 """); @@ -8942,7 +8995,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 """); @@ -9887,7 +9940,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 """); @@ -9899,7 +9952,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 """); @@ -9911,7 +9964,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 """); @@ -9923,7 +9976,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 """); @@ -9942,7 +9995,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' """); @@ -9954,7 +10007,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' """); @@ -9966,7 +10019,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' """); @@ -9978,7 +10031,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 """); @@ -9990,7 +10043,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 """); @@ -10002,7 +10055,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 """); @@ -10014,7 +10067,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 """); @@ -10026,7 +10079,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' """); @@ -10038,7 +10091,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' """); @@ -10057,7 +10110,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) @@ -10125,7 +10178,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] """); @@ -10139,7 +10192,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 """); @@ -10151,7 +10204,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) """); @@ -10688,7 +10741,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 5e9ba7444b6..ee21e1448c4 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 """); @@ -2247,7 +2247,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 """); @@ -2925,7 +2925,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 """); @@ -3027,7 +3027,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 """); @@ -3500,7 +3500,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 """); @@ -4121,7 +4121,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) """); @@ -4204,7 +4204,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() """); @@ -4391,18 +4391,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); @@ -4516,7 +4504,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 """); @@ -4805,6 +4793,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 [g].[Rank] + WHEN 0 THEN N'None' + WHEN 1 THEN N'Private' + WHEN 2 THEN N'Corporal' + WHEN 4 THEN N'Sergeant' + WHEN 8 THEN N'Lieutenant' + WHEN 16 THEN N'Captain' + WHEN 32 THEN N'Major' + WHEN 64 THEN N'Colonel' + WHEN 128 THEN N'General' + ELSE COALESCE(CAST([g].[Rank] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), 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 [w].[AmmunitionType] + WHEN 1 THEN N'Cartridge' + WHEN 2 THEN N'Shell' + ELSE COALESCE(CAST([w].[AmmunitionType] AS nvarchar(max)), 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); @@ -5705,7 +5758,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 """); @@ -6237,7 +6290,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 """); @@ -6372,7 +6425,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] @@ -6667,7 +6720,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 """); @@ -6792,7 +6845,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 """); @@ -6910,7 +6963,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 """); @@ -8698,7 +8751,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 """); @@ -9092,7 +9145,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 """); @@ -9514,7 +9567,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 87817d139b6..9c2983eacde 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 "g"."Rank" + WHEN 0 THEN 'None' + WHEN 1 THEN 'Private' + WHEN 2 THEN 'Corporal' + WHEN 4 THEN 'Sergeant' + WHEN 8 THEN 'Lieutenant' + WHEN 16 THEN 'Captain' + WHEN 32 THEN 'Major' + WHEN 64 THEN 'Colonel' + WHEN 128 THEN 'General' + ELSE COALESCE(CAST("g"."Rank" AS TEXT), '') +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 "w"."AmmunitionType" + WHEN 1 THEN 'Cartridge' + WHEN 2 THEN 'Shell' + ELSE COALESCE(CAST("w"."AmmunitionType" AS TEXT), '') +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 "w"."AmmunitionType" + WHEN 1 THEN 'Cartridge' + WHEN 2 THEN 'Shell' + ELSE COALESCE(CAST("w"."AmmunitionType" AS TEXT), '') +END, 'Cart') > 0 +"""); + } + public override async Task Correlated_collections_naked_navigation_with_ToList(bool async) { await base.Correlated_collections_naked_navigation_with_ToList(async); @@ -6574,7 +6627,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 """);