Starts in:
1 DAY
21 HRS
50 MIN
9 SEC
Starts in:
1 D
21 H
50 M
9 S
Open Closed

EF Core DateOnly support #5113


User avatar
0
pablo@ccalp.net created
  • ABP Framework version: v7.2
  • UI type: Angular
  • DB provider: EF Core

I'm trying to create an entity with a DateOnly field type, but when creating a migration I'm getting the following message:

The 'DateOnly?' property 'AccountingDeposit.BankPostingDate' could not be mapped to the database type 'date' because the database provider does not support mapping 'DateOnly?' properties to 'date' columns. Consider mapping to a different database type or converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

I'm using a value converter as suggested.

protected override void ConfigureConventions(ModelConfigurationBuilder builder)
{
    builder.Properties<DateOnly>()
        .HaveConversion<DateOnlyConverter>()
        .HaveColumnType("date");

    base.ConfigureConventions(builder);
}

Please advice on how to proceed.


1 Answer(s)
  • User Avatar
    0
    nlachmuthDev created

    Hi there,

    what DBMS do you use? (MySql, Mssql, PostgreSQL)

    Nevertheless you should not need to provide that convenstion override and specify the DateOnlyConverter for DateOnly Props.

    I created a fresh application (ABP Framework Version 7.2.2) using MySql as DBMS and added a TestEntity with nullable DateOnly Property:

    public class NullableDateOnlyTestEntity : AggregateRoot<Guid>
    {
        public DateOnly? ValidFrom { get; set; }
    }
    

    After adding the DbSet for this entity, the migration could be created without specifing the value converter. Here is the resulting Migration:

    As you can see the db column type would be date.

    So please try to create the migration again without specifying the exact value converter.

    Greetings Nico

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06