question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Skip/Take parameter types misconfigured

See original GitHub issue

Hi. I’m trying to make EF Core work with pg_trgm extension. Here is stripped down sample application to demonstrate issue https://github.com/osovitskiy/npgsql-efcore-sample While simple query like

context.Parent.Where(x => x.Name.FuzzyMatches("foobar")).ToList();

executes fine, more complex query with pagination

var entities = 
    context.Entities
           .Where(x => 
               context.Entities
                      .Where(y => y.Name.FuzzyMatches(search))
                      .OrderBy(y => y.Name.WordSimilarity(search))
                      .Skip(skip)
                      .Take(take)
                      .Select(y => y.Id)
                      .Contains(x.Id))
           .OrderBy(x => x.Name.WordSimilarity(search))
           .ToList();

translates correctly

SELECT x."Id", x."Name"
FROM "Entities" AS x
WHERE x."Id" IN (
    SELECT y."Id"
    FROM "Entities" AS y
    WHERE (y."Name" %> @__search_0) = TRUE
    ORDER BY (y."Name" <->> @__search_0)
    LIMIT @__take_2 OFFSET @__skip_1
)
ORDER BY (x."Name" <->> @__search_0)

but fails to execute with error System.InvalidCastException: Can't write CLR type System.String with handler type Int32Handler because it tries to write @__search_0 parameter as Int32.

Same expression works fine if I replace FuzzyMatches call with any of string.Contains / EF.Functions.Like / EF.Functions.ToTsVector().Matches(). Any suggestions?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Jul 22, 2019

Let’s revisit it after we port to preview7. So much is changing there that the problem may go away (or its resolution may be very different).

0reactions
rojicommented, May 24, 2020

Revisiting this after a long time, and @austindrenski’s simplified repo works fine on EF Core 3.1. Many type mapping inference issues were fixed in 3.0, so it would make sense this works now.

If there’s still an issue here, please post back and I’ll revisit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Skip/Take on a type not know at compile-time
I'd like to write a function, that retrieves data from a database table page by page. The goal here is to save memory....
Read more >
ORA-12700: invalid NLS parameter value
Cause: Either an attempt was made to issue an ALTER SESSION command with an invalid NLS parameter or value; or the environment variable(s)...
Read more >
HDevelop User's Guide
This manual is a guide to HDevelop, the interactive development environment for the HALCON machine vision library. It is intended for users who...
Read more >
Configuring parameters and parameter data types
Command objects use parameters to pass values to SQL statements or stored procedures, providing type checking and validation in ADO.NET.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found