asp.net-coreasp.net-core-webapisystem.data.sqlitemicrosoft.data.sqlite

How to deal with SQLite in an asynchronous project


SQLite is not asynchronous, and the exposed Microsoft.Data.Sqlite ADO.net *Async methods are implemented synchronously under the hood.

My question: how would you use SQLite in a asp.net core 5 API project which could benefit from asynchronous code, and also the async/await keywords to coordinate it?

I see two options

Which one do you think would be better?

Thanks!


Solution

  • I would tend to use the synchronous Async methods, but it's not a strong preference. The only reason I'd prefer Async is just in case either a different database is used in the future, or SQLite gets real asynchronous methods in a future release.

    What you definitely want to avoid is await Task.Run.