DapperLib / DapperLib/Dapper

SqlMapper.AddTypeHandler doesnt reset internal deserializer cache

Open
#885 3 comments 2 reactions 1 assignee View on GitHub

@mgravell is already working on this.

Since Nov 26, 2017.

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

Description

If you run a query for a given type e.g.
connection.Query<Foo>("select * from Foo where Id = @id", new {id });
the Foo type will get cached in SqlMapper._queryCache and along with it the deserizlier for Foo.

If you then were to add a TypeHandler for one of the properties on Foo e.g.
SqlMapper.AddTypeHandler(new FooPropertyTypeHandler());

The SqlMapper._queryCache cache for Foo type is not busted. So next time you go to run your Foo query as shown above it will not use the new type you just registered.

While it is odd to register a type handler after querying the type, it seems like a bug that the cache doesn't get busted.
I found this out because I was registering my type handlers in a static constructor for the class. I then re-read how static constructors work and have since changed my approach.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.