DapperLib / DapperLib/Dapper

Different TypeHandler for different database types

Open
#1,668 3 comments 2 reactions 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,

is there a way to tell Dapper to use specific TypeHandlers depending on the type of database (e.g. SQLite/SQL Server/MySQL/etc.) that is being queried?

My situation:
I am using Dapper to query data from a SQLite db and a SQL Server db in the same application.

For SQLite I have implemented some custom TypeHandlers.
For example I have a TypeHandler that converts System.DateTime values to strings and strings back to DateTimes.

This causes a problem now, when I use Dapper to query data from SQL Server.
SQL Server (more precisely the SQL Server ADO.NET provider) already returns datetime values as instances of the System.DateTime type, but my (SQLite specific) TypeHandler expects date times values to be retrieved as strings from the database.

Now, I know I could examine the value returned from the database in my TypeHandler and act accordingly, but there are some downsides to this approach.

Ideally I would like Dapper to use one TypeHandler for SQLite and another for SQL Server.

Is this possible?
Or is there maybe some way I can determine the database type from inside the TypeHandler?

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

No file, test, or entry point is identified. Start by locating Dapper's TypeHandler registration and provider interaction, then determine whether handlers can be scoped by database type; done requires a documented, tested answer or a clearly scoped implementation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql, sqlite
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.