Skip to content

Commit

Permalink
Add suppress warning for ordinal string comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
aeshub committed Nov 10, 2023
1 parent 00b4554 commit fc3f891
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
25 changes: 0 additions & 25 deletions backend/api/Database/Context/FlotillaDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,6 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura
configurationBuilder.Properties(typeof(Enum)).HaveConversion<string>();
}

// 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<TOwnerEntity, TDependentEntity>(
ref OwnedNavigationBuilder<TOwnerEntity, TDependentEntity> 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<T>(ref EntityTypeBuilder<T> entity)
where T : class
{
Expand Down
8 changes: 7 additions & 1 deletion backend/api/Services/InspectionService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,11 @@ public interface IInspectionService
public Task<Inspection> 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;
Expand Down
8 changes: 7 additions & 1 deletion backend/api/Services/MissionTaskService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,11 @@ public interface IMissionTaskService
public Task<MissionTask> 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;
Expand Down

0 comments on commit fc3f891

Please sign in to comment.