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

Map User Defined Function return table value with parameter timestamp without time zone #3143

Closed
vancodocton opened this issue Mar 29, 2024 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@vancodocton
Copy link

vancodocton commented Mar 29, 2024

I tried to config the parameter stored type is timestamp without timezone. However, runtime exception is thrown:

Unhandled exception. System.InvalidCastException: Cannot write DateTime with Kind=Unspecified to PostgreSQL type 'timestamp with time zone', only UTC is supported. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior.

Here is my repo to repro issue that I met. https://github.com/vancodocton/Npgsql.Labs

@vancodocton
Copy link
Author

        var method = typeof(ApplicationDbContext).GetMethod(nameof(Demo),
            new[]
            {
                typeof(DateTime),
                typeof(DateTime),
            }) ?? throw new InvalidOperationException();

        modelBuilder.HasDbFunction(method, builder =>
        {
            builder.HasParameter("in_from_dt")
                .HasStoreType("timestamp without time zone");
            builder.HasParameter("in_to_dt")
                .HasStoreType("timestamp without time zone");
        });

I tried to config parameter store type, but is doesn't work.

@roji
Copy link
Member

roji commented Mar 29, 2024

Duplicate of dotnet/efcore#25980

@roji roji marked this as a duplicate of dotnet/efcore#25980 Mar 29, 2024
@roji
Copy link
Member

roji commented Mar 29, 2024

Yeah, unfortunately this is a known bug in EF itself - there's nothing that can be done in the PG provider specifically. Make sure to upvote the above issue and follow it for updates.

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
@roji roji added the duplicate This issue or pull request already exists label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants