System.Data.SQLite 对比 Microsoft.Data.Sqlite

System.Data.SQLite vs Microsoft.Data.Sqlite

System.Data.SQLite和Microsoft.Data.Sqlite有什么区别?

我知道 System.Data.SQLite 比较老,在 Microsoft.Data.Sqlite 之后获得了 .NETStandard 支持,但现在他们都支持 .NETStandard 2。

两者相比有什么优势?

System.Data.SQLite 的一个优点是它是由 SQLite 团队开发的,该团队已声明长期致力于保持对它的支持。

Microsoft.Data.Sqlite 的一个优点是它是由 Microsoft 开发的,可以假设它已经通过 Entitity Framework、.NET Core 等进行了很好的测试

我为我的项目选择了 System.Data.SQLite,原因之一是我使用了 Microsoft.Data.Sqlite 中“不支持”的 GetBytes() DataReader 方法。

我没有测试过性能,但是如果 Microsoft.Data.Sqlite 获胜我也不会感到惊讶,因为它声称是一个更薄的包装器。见下文。

此处 Microsoft.Data.Sqlite 开发人员之一 Brice Lambson 发表了一条信息丰富的评论:https://www.bricelam.net/2018/05/24/microsoft-data-sqlite-2-1.html#comment-3980760585

他说,

"There are three main differences between Microsoft.Data.Sqlite and System.Data.SQLite.

"First, we don't aim to be a feature-complete ADO.NET provider. Microsoft.Data.Sqlite was created for .NET Core 1.0 when the goal was to create a lighter-weight, modernized version of .NET. That goal of .NET Core has largely been abandoned in favor of adding as many APIs as possible to make it easier to port from other .NET runtimes. However, the goal of Microsot.Data.Sqlite is still just to provide a basic ADO.NET implementation sufficient to support modern data access frameworks like EF Core, Dapper, etc. We tend not to add API for things that can be done using SQL. For example, see this comment for SQL alternatives to connection string keywords.

"The second big difference is that we're much closer to the native SQLite behavior. We don't try to compensate for any of SQLite's quirkiness. For example, System.Data.SQLite adds .NET semantics to column type names. They even have to parse every SQL statement before sending it to the native driver to handle a custom SQL statement for specifying the column type of results not coming directly from a table column (i.e. expressions in the SELECT clause). Instead, we embrace the fact that SQLite only supports four primitive types (INTEGER, REAL, TEXT, and BLOB) and implement ADO.NET APIs in a way that helps you coerce values between these and .NET types.

"Finally, we weren't written 10 years ago. :-) This allow us to create more modern APIs that feel more natural in modern, idiomatic C#. The API for registering user-defined functions is the best example of this."

我在一个项目中尝试了System.Data.SQLite和Microsoft.Data.SQLite,我做了一个真实世界的性能测试,System.Data.SQLite在批量插入时比Microsoft.Data.Sqlite快大约3倍.

还有一个发现,截至今天(2020 年 3 月 6 日),System.Data.SQLite 没有为 linux arm 提供已编译的二进制文件。你必须这样做 manually.