Skip to content

Commit

Permalink
Add value converters for DateTimeOffset properties
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Mar 9, 2022
1 parent 8bf8995 commit 038d286
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Hammer/Data/EntityConfigurations/MessageEditConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Hammer.Data.ValueConverters;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Hammer.Data.EntityConfigurations;

Expand All @@ -14,5 +15,7 @@ public void Configure(EntityTypeBuilder<MessageEdit> builder)
{
builder.Property(e => e.AttachmentsAfter).HasConversion<UriListToBytesConverter>();
builder.Property(e => e.AttachmentsBefore).HasConversion<UriListToBytesConverter>();
builder.Property(e => e.CreationTimestamp).HasConversion<DateTimeOffsetToBytesConverter>();
builder.Property(e => e.EditTimestamp).HasConversion<DateTimeOffsetToBytesConverter>();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Hammer.Data.EntityConfigurations;

Expand All @@ -12,5 +13,7 @@ public void Configure(EntityTypeBuilder<TrackedMessage> builder)
builder.Property(e => e.Attachments)
.HasConversion(a => string.Join("\n", a),
s => s.Split('\n', StringSplitOptions.RemoveEmptyEntries).Select(u => new Uri(u)).ToList());
builder.Property(e => e.CreationTimestamp).HasConversion<DateTimeOffsetToBytesConverter>();
builder.Property(e => e.DeletionTimestamp).HasConversion<DateTimeOffsetToBytesConverter>();
}
}

0 comments on commit 038d286

Please sign in to comment.