Non Nullable Instant receives Cannot scaffold C# literals of type 'NodaTime.Instant'.
See original GitHub issueWhile researching this issue I stumbled across the previously documented bug https://github.com/npgsql/efcore.pg/issues/624 which leads you to https://github.com/dotnet/efcore/issues/8741 .
- I am not scaffolding data on the object the Instant property exists on.
- When the Instant type is nullable I am able to use migrations
- When the Instant type is not nullable it produces the Cannot scaffold C# literals of type ‘NodaTime.Instant’. error
- I have a number of objects using a nullable Instant
public Instant? LastActivity { get; set; }
This produces migrations without trouble.
public Instant LastActivity { get; set; }
Produces:
System.InvalidOperationException: Cannot scaffold C# literals of type 'NodaTime.Instant'. The provider should implement CoreTypeMapping.GenerateCodeLiteral to support using it at design time.
at Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.UnknownLiteral(Object value)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(AddColumnOperation operation, IndentedStringBuilder builder)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid3[T0,T1,T2](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationOperationGenerator.Generate(String builderName, IReadOnlyList`1 operations, IndentedStringBuilder builder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMigration(String migrationNamespace, String migrationName, IReadOnlyList`1 upOperations, IReadOnlyList`1 downOperations)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
EF Core - Scaffolding to NodaTime types?
I would like to get possibility that anytime I need to scaffold model (i.e. model has changed) I will always obtain the same...
Read more >Struct Instant | Noda Time
An Instant has no concept of a particular time zone or calendar: it simply represents a point in time that can be globally...
Read more >Noda Time | Text handling
Most of the core Noda Time types ( LocalDateTime , Instant etc) provide methods with the following signatures: ToString() : Formats the value...
Read more >Noda Time | Serialization
As of Noda Time 1.2, the following types implement IXmlSerializable and can therefore be serialized: Instant; OffsetDateTime; ZonedDateTime; LocalDateTime ...
Read more >The Tidelift catalog of open source packages
Traitlets is a framework that lets Python classes have attributes with type checking, dynamically calculated default values, and "on change" callbacks.
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
I moved on from this original post and instead just decided to keep them non-nullable to continue work. At some point during this I must have unknowingly corrected whatever was causing this issue. I began rewriting the original code and in the process I decided to make them nullable again and I can now create migrations without trouble. I wish I could provide more insight on my original issue.
I ran into the same issue but with version 3 of EFCore. I want to create migrations for LibraryA, but run the tool in the context of ProjectA. ProjectA already had a transitive dependency on “Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime” through LibraryB. LibraryA neither had a (transitive) dependency on LibraryB nor on “Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime”. So the command I use is like this:
ProjectA> dotnet ef migrations add --context MyDbContext --project ../LibraryA MyMigration
.Adding a direct dependency on “Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime” to either ProjectA or LibraryA fixed the problem. Possibly having a transitive dependency in LibraryA would suffice, but I haven’t tested that.