-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
F# Anonymous records support in query results #1226
Comments
I'll try to address that and send a PR. I think dapper can fallback to search for a constructor with parameters sorted by name too, if is not found with query column order. |
done in PR #1233 ready to review |
+1 |
Just a question on this - we're using Dapper and Anonymous Records with some success in F#4.6/7. The only issue we're finding is that Dapper appears to be looking for a constructor with the parameters in a specific order, rather than simply looking for the correct parameters in any order. This somewhat limits the utility of F# in general with Dapper since you need to align the order of field declarations on a record with the fields that come back from SQL. Is this by design? |
@isaacabraham it’s by design of F# F# use .NET anonymous classe of for anonimous types, and these have constructor params by order of definition. See the linked dotnet/fsharp issue. Other .NET Lang doesn’t know about it. F# compiler support equality by name of fields (c# doesn’t, strict by order) |
Yep, I know. I'm just wondering about whether Dapper could match by name rather than order though. |
@isaacabraham that's what PR #1233 fixes |
Ah, great. I got confused from the title - anonymous records are currently supported. If it's matching by name not order it's more about handling F# records better in general. Currently we are decorating records with |
@isaacabraham not really. let res = db.QuerySingle<{| Tid: int; Name: string; X:string; Y: int |}>("select Tid=20, Name='fdsf', X='hfds', Y=15") where you think it should works (same order of anon record field and query args), but doesnt at runtime |
I ran into this last night. It is very tricky when you got it accidently right in the first place and find out later with more parameters that it does not behave like expected. Are there any news on this issue? May I help somehow? |
+1, had this error today. My error states this:
Update: In my situation, I was abble to make it work using {| Value: int64 |} |
F# 4.6 added anonymous record support
These are similar to C# anonymous classes, but by design, the fields are sorted by name on creation so declaration order doesnt matter (
{| X=5; Y=6|} = {| Y=6; X=5 |}
)In dapper this create an issue when are used as a result type.
the error explain it doesnt find the constructor with right shape
As note:
and
ref dotnet/fsharp#6422
The text was updated successfully, but these errors were encountered: