简体   繁体   English

与 SQLite Dapper 的多个连接

[英]Multiple Connections to SQLite Dapper

I am using Dapper with my SQLite database.我在 SQLite 数据库中使用 Dapper。 I have developed some multi-threaded code where each thread performs some read and write operations using Dapper ORM.我开发了一些多线程代码,其中每个线程使用 Dapper ORM 执行一些读写操作。 Both the thread may very much try to concurrently write on the same table as well.两个线程也可能会尝试在同一个表上同时写入。

The confusion I am facing is that do I have to implement some technique in my code to make the concurrent reads thread safe or do dapper will handle that for me.我面临的困惑是我是否必须在我的代码中实现一些技术来使并发读取线程安全,或者 dapper 会为我处理这个问题。

Do note I am familiar that SQLite is the one locking the db file for write and my only concern here is about Dapper and what it does in such scenario.请注意,我很熟悉 SQLite 是锁定 db 文件以进行写入的那个,我在这里唯一关心的是 Dapper 以及它在这种情况下的作用。

As you said, SQLite implements locking on DB file level.正如您所说,SQLite 在 DB 文件级别实现锁定。

Dapper or any other full or micro ORM cannot change this fact. Dapper 或任何其他完整或微型 ORM 都无法改变这一事实。 No ORM will implement thread management or concurrency for any RDBMS.没有 ORM 会为任何 RDBMS 实现线程管理或并发。 Thread management is responsibility of user.线程管理是用户的责任。

Think other way.换个方式想想。 How ORM will know how to implement threading? ORM 如何知道如何实现线程?

Yes;是的; some ORMs manage connection up to certain level.一些 ORM 管理连接到一定级别。 But mostly, it is only limited to creating/opening/disposing it.但大多数情况下,它仅限于创建/打开/处置它。 ORMs do not control threading or concurrency. ORM 不控制线程或并发。 It is something to be implemented by user.它是由用户来实现的。

Response to your comment:回复您的评论:

but yet the question still stays what dapper does in such cases as it may have some sort of retry logic to try execute the query again in case the lock is there但问题仍然是在这种情况下 dapper 会做什么,因为它可能有某种重试逻辑来尝试再次执行查询,以防锁定在那里

Dapper don't do anything like that. Dapper 不会做这样的事情。 Dapper works exactly (well... almost) like ADO.NET. Dapper 的工作原理与 ADO.NET 完全一样(好吧……几乎)。 For any querying part, Dapper is not much functionally different than ADO.NET.对于任何查询部分,Dapper 在功能上与 ADO.NET 没有太大区别。

So, to answer your comment, if some provider of ADO.NET implement retry logic, it will be inherited by Dapper automatically.所以,回答你的评论,如果 ADO.NET 的某些提供者实现重试逻辑,它将被 Dapper 自动继承。 But, Dapper on itself do not implement any such logic.但是,Dapper 本身并没有实现任何这样的逻辑。

If I guess correctly, ADO.NET will throw proper exception - Dapper will simply pass on that exception to you.如果我猜对了,ADO.NET 会抛出正确的异常 - Dapper 只会将该异常传递给您。

I hope this answer will help you.我希望这个答案对你有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM