Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment DateTimeOffset with value converter #33190

Closed
paulomorgado opened this issue Feb 28, 2024 · 1 comment
Closed

Increment DateTimeOffset with value converter #33190

paulomorgado opened this issue Feb 28, 2024 · 1 comment

Comments

@paulomorgado
Copy link
Contributor

I have this model that has DateTimeOffset properties that I need to use in Sqlite.

I've added this value converter:

public override void Customize(ModelBuilder modelBuilder, DbContext context)
{
    base.Customize(modelBuilder, context);

    var dateTimeOffsetToDateTimeConverter = new ValueConverter<DateTimeOffset, DateTime>(
        v => v.DateTime,
        v => new DateTimeOffset(v));

    foreach (var entityType in modelBuilder.Model.GetEntityTypes())
    {
        foreach (var property in entityType.GetProperties())
        {
            if (property.ClrType == typeof(DateTimeOffset))
            {
                property.SetValueConverter(dateTimeOffsetToDateTimeConverter);
            }
        }
    }
}

However, when using ExecuteUpdateAsync Sqlit cannot translate the query:

... could not be translated. Additional information: Translation of method 'System.DateTimeOffset.AddHours' failed.

Is there a way around this?

@ajcvickers
Copy link
Member

Duplicate of #10434

@ajcvickers ajcvickers marked this as a duplicate of #10434 Mar 4, 2024
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants