c#

I am writing an application that need to run in iOS, Android, Windows Phone, WPF, Windows 8 Metro, Linux and Mac. I have about 95 % of the code in the cross-platform realm but the UI and some things obviously needs to be coded specifically for each platform.

Now, we need to add some very simple database support in the app and I would love to work against Sqlite from the cross-platform realm in my code. Can this be done with any existing Sqlite wrapper or do I need to create my own? Or should I use several Sqlite wrappers that have the same syntax and just reference different libraries from my different csproj files (per platform)?

I have read this Q/A Is there a .NET/C# wrapper for SQLite? but after an hour of reading I am still unsure how to get things working on all those platforms so I thought that somebody might have thought about these things before me.


Some options for cross-platform .NET/C# development with SQLite are:

SQLitePCL.raw

A Portable Class Library (PCL) for low-level (raw) access to SQLite

SQLitePCL.raw provides a very thin C# wrapper ontop of the SQLite C API. The API exposed by SQLitePCL.raw is hostile from an application developer perspective, but is designed for use as a common portable layer upon which friendlier wrappers can be built.

License : Apache License v2

Source code : https://github.com/ericsink/SQLitePCL.raw

Nuget : https://www.nuget.org/packages/SQLitePCLRaw.core

Platforms : Xamarin.Android, Xamarin.iOS, UWP, Windows Phone 8.1, .NET 4.5, .NET 4.0, .NET 3.5, Linux, MacOS, NetStandard 1.1, Windows Phone 8 (with limitations), Windows Phone 8.1 Silverlight (with limitations)


SQLitePCL.pretty

A pretty face on top of SQLitePCL.raw

This library wraps the C like SQLiteAPI provided by SQLitePCL.raw with a friendly C# object oriented API. SQLitePCL.pretty has extensive unit test coverage and supports many newer features available in more recent SQLite versions.

License : Apache License v2

Source code : https://github.com/bordoley/SQLitePCL.pretty

Nuget : https://www.nuget.org/packages/SQLitePCL.pretty

Platforms : same as SQLitePCL.raw


SQLite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET

SQLite-net was designed as a quick and convenient database layer. Very easy to integrate with existing projects and runs on all the .NET platforms, with very simple methods for executing CRUD operations and queries safely (using parameters) and for retrieving the results of those query in a strongly typed fashion.

License : MIT License

Source code : https://github.com/praeclarum/sqlite-net

Nuget : https://www.nuget.org/packages/sqlite-net-pcl

Platforms : same as SQLitePCL.raw


Microsoft.Data.Sqlite

SQLite implementations of the System.Data.Common interfaces

This project is part of ASP.NET Core and maintained by Microsoft

License : Apache License v2

Source code : https://github.com/aspnet/Microsoft.Data.Sqlite

Nuget : https://www.nuget.org/packages/Microsoft.Data.SQLite

Platforms : .NET Framework, Mono, .NET Core (.NET Native, CoreCLR, Windows Universal), Xamarin (planned)


I'd recommend using the Mono version (http://www.mono-project.com/SQLite) of the SQLite wrapper. The wrapper itself is written entirely in managed code and you just need to provide the Sqlite library for the respective environment.

I had a C# project that ran on both linux and windows by doing that.

You MIGHT be able to get away with using the official C# wrapper (http://system.data.sqlite.org/) but I am unsure on how it deals with multiple platforms.

链接地址: http://www.djcxy.com/p/19762.html

上一篇: 我如何防止SQLite数据库锁?

下一篇: C#