C
C#2y ago
Kosta

❔ How to map dateonly and timeonly?

Getting this error when trying to do a migration:
The property 'UserData.CreatedDate' could not be mapped because it is of type 'DateOnly', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
The property 'UserData.CreatedDate' could not be mapped because it is of type 'DateOnly', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
3 Replies
HimmDawg
HimmDawg2y ago
Which db provider are you using? Independent from the provider tho, you can use
builder
.Entity<YourEntity>()
.Property(x => x.TheProperty)
.HasConversion<ValueConverter>()
builder
.Entity<YourEntity>()
.Property(x => x.TheProperty)
.HasConversion<ValueConverter>()
with a custom ValueConverter<T1, T2>.
Kosta
Kosta2y ago
gotcha, thx!
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.