How to use alternate type "REAL" (JulianDay) for DateTimes in EFcore?
See original GitHub issueMicrosoft.Data.Sqlite has support for this: https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/types#alternative-types : Using REAL (JulianDay) instead of TEXT (ISO8601 formatted string).
But how do I enable this for EFcore for newly written data? (Reading existing databases already seems to work fine)
I tried
builder.Property("name").HasColumnType("REAL")
and
builder.Property("name").HasConversion<double>()
or .HasConversion<float>()
I tried both each other exclusive and in combination:
HasColumnType
only reflects increate table
but uses still TEXT for new data (used SQLite’stypeof()
function to verify)HasConvertion
just fails on creating initial SQL
In contrast in order to use binary blob GUIDs (instead of strings) just works by using .HasColumnType("BLOB").HasConversion<byte[]>()
.
I fear I have to write a converter which calculates the JulianDay in advance?
[EF 5.0.5 on netcore3.1 and net5]
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
c# - SQLite DATETIME (in Julian/Real/Double) column with ...
I have an existing SQLite database that I am calling with Entity Framework Codefirst. The dates are entered into SQLite (by a non...
Read more >Going down the rabbit hole of EF Core and converting strings ...
I am working on a greenfield project that uses EF Core 6 with AspNetCore 6 at ... Try converting the string to a...
Read more >Working with calendars
This topic explores the support for calendars in .NET and discusses the use of the calendar classes when working with date values.
Read more >DateTime.Kind comes back as Unspecified · Issue #4711
I cannot see to find a simple way of doing this in our new EF Core setup, that uses an existing schema (and...
Read more >2.1.16 Dates and Times in Origin
Starting with Origin 2019, Origin offers two alternate date-time systems - a true Julian Date system and a "2018" system in which t0...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We discussed this as a team, and decided that it would be good if the EF Core SQLite provider handled this automatically.
.Property(e =>e.Char).HasColumnType("INTEGER")
.Property(e =>e.DateTime).HasColumnType("REAL")
.Property(e =>e.DateTimeOffset).HasColumnType("REAL")
.Property(e =>e.Guid).HasColumnType("BLOB")
.Property(e =>e.TimeSpan).HasColumnType("REAL")
📝 Note to implementor: The SQL literal format should also reflect the mapping.
The method translators will also need to be updated to understand the conversion.