Dapper does not currently support custom build logic; I assume that you are asking for something like:
class Post {} class Question : Post { .. } class Answer : Post { ... } Func<IDbDataReader, Func<IDbDataReader, Post>> factoryLocator = ... my magic factory locater; cnn.Query<Post>(@" select * from Posts p left join Questions q on q.Id = p.Id left join Answers a on a.Id = p.Id", factoryLocator: factoryLocator);
We decided not to apply such a logical reason, so we never had to solve such a problem in real life. It also introduces sufficient internal complexity and sufficient external complexity (since you need to enable post is Question
).
I am not categorically against including this feature, if you can make a good argument for including, and the patch is simple. I also want to add hooks to Dapper so you can introduce such functions.
As for the caching strategy, we find that in the general case, we never inflate the cache; inflating occurs only if you abuse dapper, say, by creating non-parameterized SQL. I fully support adding a hook that will allow you to specify your own cache provider instead of the one used by ConcurrentDictionary
.
source share