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.

The current CSharpHelper cannot scaffold literals of type 'NodaTime.OffsetTime'. Configure your services to use one that can.

See original GitHub issue

Having issues with time. Like so few other people I assumed Timestamp with time zone stored time zone information. Trying to correct my mistake by switching to NodaTime now. I switched all my DateTimeOffset’s to Instant, and my DateTime?'s to LocalDate?'s. Creating a migration to make the change wasn’t working so I just regex’ed my ModelSnapshot, Migrations and Designer files to use the appropriate type. That worked fine but running into problems trying to make a Time with time zone column so I can separately store the time of day information in Postgres. Whenever I try to scaffold a migration I get the error

The current CSharpHelper cannot scaffold literals of type ‘NodaTime.OffsetTime’. Configure your services to use one that can.

Here is the model I am trying to make the migration for (with several properties omitted).

public class Event 
{
    public Instant Start { get; set; }
    public OffsetTime StartTimeOfDay { get; set; }
    public Instant? End { get; set; }
    public OffsetTime? EndTimeOfDay { get; set; }
}

Saw something about it possibly being project references so here are my refs. Tried to play around with them but was unsuccessful.

  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="7.0.1" />
    <PackageReference Include="AutoMapper.Extensions.ExpressionMapping" Version="1.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1.1" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime" Version="2.1.1" />
  </ItemGroup>

Also tried switching to DateTimeOffset and using [Column(TypeName = "time with time zone")] and the migration worked but got a TimeTzHandler cannot convert to DateTimeOffset error when trying to save any entities.

I did try making a fresh solution and context and it did successfully create an initial migration with the above model even when the dbcontext was in a separate solution

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
rojicommented, Sep 1, 2018

For the root cause here see #575 (which is actually https://github.com/aspnet/EntityFrameworkCore/issues/8741).

0reactions
austindrenskicommented, Sep 1, 2018

@WarrenFerrell Glad to hear it worked out. Please do let us know if you end up finding the root cause, happy to reopen at that time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The current CSharpHelper cannot scaffold literals of type ' ...
The current CSharpHelper cannot scaffold literals of type 'NodaTime.OffsetTime'. Configure your services to use one that can. Here is the model ...
Read more >
Migrations Error - cannot scaffold literals of type ...
I then get the following error: The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.
Read more >
Noda Time | Text handling
A pattern is an object capable of parsing from text to a specific type, and formatting a value to text. Parsing and formatting...
Read more >
Noda Time | Choosing (and converting) between types
The following diagram shows various different ways of converting between the types.
Read more >
Noda Time | Migrating from 1.x to 2.0
The static method is self-describing, and this allows the constructor to be rewritten for use within Noda Time itself. The LocalTime.LocalDateTime property has ......
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