[英]Can you use Dapper to refresh existing object references rather than always returning new ones?
TLDR version: TLDR版本:
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? 是否可以使用Dapper ORM手动将已存在的内存中对象实例更新为DB中的最新值,而不是始终返回新实例?
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. 同时,我们非常喜欢Dapper如何通过使用匿名类型指定参数的简单SQL调用来创建和返回对象的便利性。 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. 我们不在乎它是否是一个我们必须明确调用的手动过程,但是我没有看到任何方法来拦截Dapper'new'ing up the objects,而是将它们交给对象进行更新。
So, can Dapper do anything like that, or is that something we're going to have to implement on our own? 那么,Dapper可以做任何类似的事情,还是我们必须自己实施的东西呢?
No, Dapper does not have any sort of persistence, observable, or reusable mechanic. 不,Dapper没有任何持久性,可观察性或可重复使用的机制。 All you can do is re-query and reassign to your existing object. 您所能做的就是重新查询并重新分配给现有对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.