mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-12 03:10:57 +08:00
Updated 常见问题 (markdown)
54
常见问题.md
54
常见问题.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.添加包
|
||||
|
||||
```
|
||||
<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.0.100" />
|
||||
<PackageReference Include = "Microsoft.Data.Sqlite" Version="6.0.3" />
|
||||
```
|
||||
|
||||
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<ISQLite>().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)
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user