question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use alternate type "REAL" (JulianDay) for DateTimes in EFcore?

See original GitHub issue

Microsoft.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 in create table but uses still TEXT for new data (used SQLite’s typeof() 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:open
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
bricelamcommented, Apr 26, 2021

We discussed this as a team, and decided that it would be good if the EF Core SQLite provider handled this automatically.

Configuraiton SqliteParameter.SqliteType
.Property(e =>e.Char).HasColumnType("INTEGER") Integer
.Property(e =>e.DateTime).HasColumnType("REAL") Real
.Property(e =>e.DateTimeOffset).HasColumnType("REAL") Real
.Property(e =>e.Guid).HasColumnType("BLOB") Blob
.Property(e =>e.TimeSpan).HasColumnType("REAL") Real

📝 Note to implementor: The SQL literal format should also reflect the mapping.

0reactions
bricelamcommented, Apr 27, 2021

The method translators will also need to be updated to understand the conversion.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found