From 5ef07efd10849659ed813ba1cd3cfb89a96a566f Mon Sep 17 00:00:00 2001 From: Alex chow Date: Sun, 13 Mar 2022 15:41:12 +0100 Subject: [PATCH] =?UTF-8?q?Updated=20=E5=B8=B8=E8=A7=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(markdown)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 常见问题.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/常见问题.md b/常见问题.md index 2c6e8ac..772b49d 100644 --- a/常见问题.md +++ b/常见问题.md @@ -113,4 +113,58 @@ GetAsync await 为异步方法获取连接的排队数量 注意:尽量不要使用 fsql.Ado.MasterPool.Get() 或 GetAsync() 方法,否则请检查姿势。 +--- + +### 9、多平台代码参考,使用自定义SqliteProvider,例如Sqlite用Microsoft.Data.Sqlite或者反射Mono.Data.Sqlite. + +[arm/树莓派](https://github.com/densen2014/FreeSqlDemos/tree/master/ARM_ConsoleApp) + +1.添加包 + +``` + + +``` + +2.代码 + +``` +Microsoft.Data.Sqlite.SqliteConnection _database = new Microsoft.Data.Sqlite.SqliteConnection($"Data Source=document.db"); + +var fsql = new FreeSql.FreeSqlBuilder() + .UseConnectionFactory(FreeSql.DataType.Sqlite, () => _database, typeof(FreeSql.Sqlite.SqliteProvider<>)) + .UseAutoSyncStructure(true) + .UseNoneCommandParameter(true) //必须开启,因为Microsoft.Data.Sqlite内插处理有bug + .UseMonitorCommand(cmd => Console.Write(cmd.CommandText)) + .Build(); +``` + +[UWP](https://github.com/densen2014/FreeSqlDemos/tree/master/UWP1) + +``` +using System.Data.SQLite; + +string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db"); +SQLiteConnection _database = new SQLiteConnection($"Data Source={dbpath}"); +var fsql = new FreeSql.FreeSqlBuilder() + `.UseConnectionFactory(FreeSql.DataType.Sqlite, () => _database, typeof(FreeSql.Sqlite.SqliteProvider<>)) + `.Build(); +``` + +[Xamarin Forms,代码较多](https://github.com/densen2014/FreeSqlDemos/tree/master/xamarinFormApps) +主程序,接口获取rovider,各个平台自己实现. +``` +if (Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Android) +{ + fsql = new FreeSql.FreeSqlBuilder() + .UseConnectionFactory(FreeSql.DataType.Sqlite, () => DependencyService.Get().GetConnectionSqlite("document"), typeof(FreeSql.Sqlite.SqliteProvider<>)) + .UseNoneCommandParameter(true) + .Build(); +} +``` + +[iOS部分](https://github.com/densen2014/FreeSqlDemos/blob/master/xamarinFormApps/xamarinFormApp.iOS/SQLite_iOS.cs) + +[安卓部分](https://github.com/densen2014/FreeSqlDemos/blob/master/xamarinFormApps/xamarinFormApp.Android/SQLite_droid.cs) + --- \ No newline at end of file