Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use Dapper to refresh existing object references rather than always returning new ones?

Tags:

c#

orm

dapper

TLDR version:

Is it possible to use the Dapper ORM to manually update already-existing in-memory object instances to the latest values in the DB rather than always returning new instances?

Longer version:

We have built our own caching mechanism to support our object models. At the same time, we really like the convenience of how Dapper can create and return objects to us from simple SQL calls using anonymous types to specify the parameters. As such, we're trying to leverage both.

What we're dealing with is we make the database the gospel of the data, using triggers and such to ensure it's integrity. Then we need to refresh our existing in-memory objects to reflect those new values. We don't care if it's a manual process which we have to explicitly call, but I don't see any way to intercept Dapper 'new'ing up the objects and instead hand them an object to update.

So, can Dapper do anything like that, or is that something we're going to have to implement on our own?

like image 600
Mark A. Donohoe Avatar asked Sep 15 '15 05:09

Mark A. Donohoe


1 Answers

No, Dapper does not have any sort of persistence, observable, or reusable mechanic. All you can do is re-query and reassign to your existing object.

like image 113
David L Avatar answered Nov 15 '22 08:11

David L