FirebirdSQL / NETProvider

Firebird ADO.NET Data Provider
https://www.firebirdsql.org/en/net-provider/
Other
161 stars 66 forks source link

Translation of DateTime.UtcNow inside queries #1070

Closed alansbraga closed 2 years ago

alansbraga commented 2 years ago

Hi. I'm using openiddict-core and I'm having an issue when they try to prune all inactive connections.

They are using this query

            var date = threshold.UtcDateTime;

            var tokens = await
                (from token in Tokens.AsTracking()
                 where token.CreationDate < date
                 where (token.Status != Statuses.Inactive && token.Status != Statuses.Valid) ||
                       (token.Authorization != null && token.Authorization.Status != Statuses.Valid) ||
                        token.ExpirationDate < DateTime.UtcNow
                 orderby token.Id
                 select token).Take(1_000).ToListAsync(cancellationToken);

I've fixed changing to this

            var date = threshold.UtcDateTime;
            var expirationDate = DateTime.UtcNow;

            var tokens = await
                (from token in Tokens.AsTracking()
                 where token.CreationDate < date
                 where (token.Status != Statuses.Inactive && token.Status != Statuses.Valid) ||
                       (token.Authorization != null && token.Authorization.Status != Statuses.Valid) ||
                        token.ExpirationDate < expirationDate 
                 orderby token.Id
                 select token).Take(1_000).ToListAsync(cancellationToken);

As you can see on their issue: https://github.com/openiddict/openiddict-core/pull/1507#issuecomment-1222715770

They asked me to create this issue here to verify if you intend to translate DateTime.UtcNow inside queries.

Thank you in advance.

cincuranet commented 2 years ago

At the moment Firebird 3 is supported for EF Core exclusively. And Firebird 3 does not have support for getting UTC or handling time zones out of the box, it always works in "local" time zone. Firebird 4 brings support for that. The issue for that is here.

Thus the translation of DateTime[Offset].UtcNow is going to happen (for FB4), but full expansion for FB4 must be completed first.