From fc3f8915c9ca7a9a072a6f6779e5ede53957b04e Mon Sep 17 00:00:00 2001 From: aestene Date: Thu, 9 Nov 2023 22:32:45 +0100 Subject: [PATCH] Add suppress warning for ordinal string comparison --- .../api/Database/Context/FlotillaDbContext.cs | 25 ------------------- backend/api/Services/InspectionService.cs | 8 +++++- backend/api/Services/MissionTaskService.cs | 8 +++++- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/backend/api/Database/Context/FlotillaDbContext.cs b/backend/api/Database/Context/FlotillaDbContext.cs index 1859d6a1a..1de4f96ac 100644 --- a/backend/api/Database/Context/FlotillaDbContext.cs +++ b/backend/api/Database/Context/FlotillaDbContext.cs @@ -102,31 +102,6 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura configurationBuilder.Properties(typeof(Enum)).HaveConversion(); } - // SQLite does not have proper support for DateTimeOffset via Entity Framework Core, see the limitations - // here: https://docs.microsoft.com/en-us/ef/core/providers/sqlite/limitations#query-limitations - // To work around this, when the Sqlite database provider is used, all model properties of type DateTimeOffset - // use the DateTimeOffsetToBinaryConverter - // Based on: https://github.com/aspnet/EntityFrameworkCore/issues/10784#issuecomment-415769754 - // This only supports millisecond precision, but should be sufficient for most use cases. - private static void AddConverterForDateTimeOffsets( - ref OwnedNavigationBuilder entity - ) - where TOwnerEntity : class - where TDependentEntity : class - { - var properties = entity.OwnedEntityType.ClrType - .GetProperties() - .Where( - p => - p.PropertyType == typeof(DateTimeOffset) - || p.PropertyType == typeof(DateTimeOffset?) - ); - foreach (var property in properties) - { - entity.Property(property.Name).HasConversion(new DateTimeOffsetToBinaryConverter()); - } - } - private static void AddConverterForDateTimeOffsets(ref EntityTypeBuilder entity) where T : class { diff --git a/backend/api/Services/InspectionService.cs b/backend/api/Services/InspectionService.cs index 05fad3878..42dee5ad6 100644 --- a/backend/api/Services/InspectionService.cs +++ b/backend/api/Services/InspectionService.cs @@ -1,4 +1,5 @@ -using Api.Database.Context; +using System.Diagnostics.CodeAnalysis; +using Api.Database.Context; using Api.Database.Models; using Api.Services.Models; using Api.Utilities; @@ -10,6 +11,11 @@ public interface IInspectionService public Task UpdateInspectionStatus(string isarStepId, IsarStepStatus isarStepStatus); } + [SuppressMessage( + "Globalization", + "CA1309:Use ordinal StringComparison", + Justification = "EF Core refrains from translating string comparison overloads to SQL" + )] public class InspectionService : IInspectionService { private readonly FlotillaDbContext _context; diff --git a/backend/api/Services/MissionTaskService.cs b/backend/api/Services/MissionTaskService.cs index d000bc3a3..e6a268f00 100644 --- a/backend/api/Services/MissionTaskService.cs +++ b/backend/api/Services/MissionTaskService.cs @@ -1,4 +1,5 @@ -using Api.Database.Context; +using System.Diagnostics.CodeAnalysis; +using Api.Database.Context; using Api.Database.Models; using Api.Services.Models; using Api.Utilities; @@ -10,6 +11,11 @@ public interface IMissionTaskService public Task UpdateMissionTaskStatus(string isarTaskId, IsarTaskStatus isarTaskStatus); } + [SuppressMessage( + "Globalization", + "CA1309:Use ordinal StringComparison", + Justification = "EF Core refrains from translating string comparison overloads to SQL" + )] public class MissionTaskService : IMissionTaskService { private readonly FlotillaDbContext _context;