Dzoukr / Dapper.FSharp

Lightweight F# extension for StackOverflow Dapper with support for MSSQL, MySQL, PostgreSQL, and SQLite
MIT License
365 stars 35 forks source link

innerJoin compilation error in v2.2.0+ #41

Closed katatunix closed 2 years ago

katatunix commented 2 years ago

The code compiled OK on v2.1.0:

select {
    table "Players"
    innerJoin "Games" "Id" "GameId"
    where (eq "Players.Id" playerId.Value)
}

However with v2.2.0 and v.2.3.0, the compiler reported an error as below:

[FS3087] The custom operation 'innerJoin' refers to a method which is overloaded. The implementations of custom operations may not be overloaded.

I tried with innerJoin "Games" [ ("Id", "GameId") ] but the error is still there.

JordanMarr commented 2 years ago

There are unit tests exercising this, so it should work. Maybe the problem is because you are not following the query expression with a call to SelectAsync. For example:

select {
    table "Players"
    innerJoin "Games" "Id" "GameId"
    where (eq "Players.Id" playerId.Value)
}
|> conn.SelectAsync<Player, Game>
JordanMarr commented 2 years ago

Also, have you tried using the Linq API?

It would be something like this:

open Dapper.FSharp.LinqBuilders

let playersTable = table'<Player> "Players"
let gamesTable = table'<Game> "Games"
select {
    for p in playersTable do
    join g in gamesTable on (p.GameId = g.Id)
    where (p.Id = playerId.Value)
}
|> conn.SelectAsync<Player, Game>
katatunix commented 2 years ago

Maybe the problem is because you are not following the query expression with a call to SelectAsync.

Of course I have the SelectAsync there. The code was totally OK on v2.1.0.

Also, have you tried using the Linq API?

Let me try now, but only for investigation purpose, personally I don't like Linq :D

JordanMarr commented 2 years ago

Sure. I only asked in the spirit of troubleshooting. 😉

Dzoukr commented 2 years ago

Maybe one guess. Do you use version of F# >= 5 or having preview flag in fsproj?

https://github.com/Dzoukr/Dapper.FSharp/blob/79b891d797be73b77f462ffcb546e175be8dc549/tests/Dapper.FSharp.Tests/Dapper.FSharp.Tests.fsproj#L5

I recently changed API with using custom operation overloads and marking old methods as Obsolete... So maybe that's the issue.

katatunix commented 2 years ago

The Linq API works, except that there is a little warning on join g in gamesTable on (p.GameId = g.Id): The value g is unused. But if I change the first g to _, it becomes an error.

I'm using JetBrains Rider.

By the way, I changed my mind, Linq API is better, since it's more type-safe, especially in where clause.

Any yes, I'm using F# 5, but not having preview flag.

tskj commented 2 years ago

I have the exact same issue, also on 5. Do I really have to downgrade to dotnet core 3.1 to be able to use version > 2.1.0 of this library?

Dzoukr commented 2 years ago

Do I really have to downgrade to dotnet core 3.1 to be able to use version > 2.1.0 of this library?

Nope, please use the preview flag in fsproj. We will see where it will go with v3, but my goal is to aim directly for .NET6