Created
February 29, 2024 20:45
-
-
Save roji/7762062a1726819fb5560d46b3cf66db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await using var context = new BlogContext(); | |
await context.Database.EnsureDeletedAsync(); | |
await context.Database.EnsureCreatedAsync(); | |
public class BlogContext : DbContext | |
{ | |
public DbSet<Blog> Blogs { get; set; } | |
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) | |
=> configurationBuilder.Properties<ReadOnlyMemory<byte>>().HaveConversion<ReadOnlyMemoryConverter>(); | |
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | |
=> optionsBuilder | |
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false") | |
.LogTo(Console.WriteLine, LogLevel.Information) | |
.EnableSensitiveDataLogging(); | |
private class ReadOnlyMemoryConverter() : ValueConverter<ReadOnlyMemory<byte>, byte[]>(v => v.ToArray(), v => v); | |
} | |
public class Blog | |
{ | |
public int Id { get; set; } | |
public ReadOnlyMemory<byte> Bytes { get; set; } | |
} |
Is it on by default? Or do I have to do something?
It's enabled by default - have you seen some other behavior?
Does it allow queries comparing dates?
No, because comparing the string representations of DateTimeOffset doesn't work - imagine having different time zones there, and then comparing string representations. If you're only storing timestamps in a single timezone (e.g. UTC), you can just use DateTime, which has a default value where comparison is supported.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it on by default? Or do I have to do something?
Does it allow queries comparing dates?