DapperLib / DapperLib/Dapper

Converting a list of a type that needs a TypeHandler

Open
#1,722 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Hi!

We are using dapper with F# and MSSQL and stumbled accross a problem that - I guess - I hunted down. Give a minute to explain:

Our database has several Ids, all Guids. To distinguish those Guids we encapsulate them in single case unions, let's call one of them CapGuid here.
Of course dapper can't know there is a Guid underlying - so we we wrote a nice TypeHandler that pulls the Guid out of the capsule.

Unfortunately that doesn't work with lists of CapGuid. The problem seems to be that in

public static void PackListParameters(IDbCommand command, string namePrefix, object value)

the TypeHandlers are never called.

The TypeMappings are used (dbType = LookupDbType(item.GetType(), "", true, out ITypeHandler handler);) but the Handlers are not. So in lists our CapGuid is never converted back to Guid and the resulting commands don't work.

Best,
Wolfram

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at PackListParameters(IDbCommand command, string namePrefix, object value) and trace how LookupDbType selects a type handler for list items. Reproduce the F# and MSSQL case with a CapGuid TypeHandler, then verify that list parameters convert the encapsulated value to Guid and produce a working command.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, fsharp, sql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.