简体   繁体   English

您可以使用Dapper刷新现有的对象引用而不是总是返回新的对象引用吗?

[英]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.

相关问题 Dapper 使用第二个 ID 列而不是第一个列映射 object - Dapper maps object using second ID column rather than first 使用LINQ解析XML并填充现有对象的属性,而不是创建一个新的属性 - Parse XML using LINQ and fill existing object's properties rather than creating a new one 如何强制浏览器在现有标签页而不是新标签页中打开我的网址? - How can I force the browser to open my urls in an existing tab rather than a new one? 此Dapper查询始终返回null - This Dapper Query is always returning a null 对象池似乎正在返回对象副本,而不是对象引用 - Object pool seems to be returning an object copy rather than an object reference 使用现有对象而不是创建特定锁对象是否安全? - Is using an existing object rather than creating a specific lock object safe? .NET MVC视图返回对象名称而不是特定对象 - .NET MVC view returning object name rather than specific object 您能否在 memory 对象中使用 LINQ 而不是 SQL 服务器查询来提高性能? - Can you use LINQ with in memory objects rather than SQL Server queries to improve performance? Visual Studio XNA 4.0 Refresh - 创建新项目和打开现有项目时出现问题 - Visual Studio XNA 4.0 Refresh - Problems creating new projects and opening existing ones 什么时候应该使用字段而不是属性? - When should you use a field rather than a property?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM