Missing method exception: Value binary comparison (but should be propery)
TerenceHinrichsen opened this issue · 9 comments
Hi,
We want to stay up to date with the changes in V3, this means we need to rewrite all our current db functions to use LinqBuilders, but we have run into a hurdle and I am unsure why it is happening.
Given :
open Dapper.FSharp.MSSQL
open Dapper.FSharp.LinqBuilders
let companyTable = table'<ReadRecord> "Company" |> inSchema "Common"
let getRecordByGuidV2AO (connection : SqlConnection, transaction) guid =
let selectQuery = select { for i in companyTable do
where (isIn i.CompanyGuid [guid])}
connection.SelectAsync<ReadRecord> (selectQuery, transaction)
|> Async.AwaitTask
|> Async.map (Seq.tryHead >> Option.map ReadRecord.toDomainX)
let getRecordByGuidAO (connection : SqlConnection, transaction) guid =
let selectQuery = select { for i in companyTable do
where (i.CompanyGuid = guid )}
connection.SelectAsync<ReadRecord> (selectQuery, transaction)
|> Async.AwaitTask
|> Async.map (Seq.tryHead >> Option.map ReadRecord.toDomainX)
The function getRecordByGuidV2AO
works and tests successfully, however, the function getRecordByGuidAO
gives expection which relates to this match. I can see the test works : simple select, the only difference being that we are passing the comparison value as a parameter to the function.
I must be missing something silly, but cannot see it.
Interesting.. I assume guid
is of type System.Guid
?
Correct, using System.Guid
I'm just as puzzled as you. Your query looks OK to me.
Grasping at straws here, but can you paste the ReadRecord
type?
In addition to the ReadRecord
type, I think we will also need the calling code that consumes the getRecordByGuidAO
function.
Thanks for your help, here is the type:
type ReadRecord = {
CompanyGuid : Guid
Code : string
Name : string
Description : string
CurrencyCode : string }
The code which consumes `getRecordByGuidAO at the moment is a test using XUnit and Swensen.Unquote:
[<Fact>]
let ``Existing row is found and correct with Dapper v3`` () =
registerCustomTypes()
use connection = new SqlConnection(connectionString)
do connection.Open()
use transaction = connection.BeginTransaction("TestMustRollBack")
let context = connection, transaction
let c =
Db.Common.Company.Dapper3Company.getRecordByGuidAO context (TestData.companyGuid |> CompanyGuid.toGuid)
|> Async.RunSynchronously
test <@ c = Some TestData.testCompany @>
So this codes executes against a MSSQL server database to ensure the database structure matches the code and all the tables etc exist.
Remember that the isIn
function works perfectly, so it seems to me that the (=)
is the function causing our grief, any pointers where to look at would be appreciated.
I noticed you are opening Dapper.FSharp.LinqBuilders
.
LinqBuilders
is an old module that was renamed to Builders
in Dapper.FSharp v3.0.
Is your test project referencing the wrong version?
Yeah, we did that intentionally, wanted to do a "gradual" rewrite - many many lines which need to be redone. So our plan was to take them over systematically using the old
interface and then once we get to the functions which require the new interface we switch over to V3.
Do you suspect it is a issue which is caused by the previous version?
Not necessarily.. it just seemed odd.
I tried reverting to pre v3 and I still can't reproduce it.
I truly do not understand what happened, but I recloned the repo, redid the tests and all seems to be operating again.
Thank you so much @JordanMarr for your help in trying to find the issue!