mac*_*688 3 c# sqlite xamarin.ios ios xamarin
我用nuget包管理器下载了这个包
该示例显示:
public class SQLiteFactoryiOS : ISQLiteFactory
{
public SQLite.Net.SQLiteConnection CreateConnection(string dbName)
{
var path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), dbName);
return new SQLite.Net.SQLiteConnection(new SQLitePlatformIOS(), path);
}
}
Run Code Online (Sandbox Code Playgroud)
我面临的问题是我无法引用SQLitePlatformIOS.我甚至在源代码中找到了它,但是我无法访问.Platform命名空间,因此我无法创建SQLitePlatformIOS对象.
using SQLite.Net; //.Platform.XamarinIOS <-- Compiler error if I try to reach this
Run Code Online (Sandbox Code Playgroud)
我用来引用它的项目是一个可移植的类项目,因为在references文件夹中我看到了.NET Portable Subset.
该项目的结构是
iOS MainProject引用示例可移植项目示例可移植项目引用SQLite.Net-PCL
在我的便携式项目中
References
.NET Portable Subset
From Packages
SQLite.Net
Packages
SQLite.Net-PCL
Data
Repositories
ExampleRepository.cs
Run Code Online (Sandbox Code Playgroud)
我的示例存储库是
using System;
using Example.Data.DTO;
using Example.Models.Properties;
using SQLite.Net;
namespace Example.Data.Repositories
{
public class ExampleRepository(string dbPath)
{
using (var db = new SQLite.Net.SQLiteConnection(new SQLitePlatformIOS() /* Can't reference */, dbPath))
{
db.CreateTable<ExampleDTO>();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我从iOS项目中调用此类.
partial void SaveObject(NSObject sender)
{
var objectToSave = CreateObjectFromView();
var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Test.db3");
var repo = new ExampleRepository(dbPath);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2701 次 |
| 最近记录: |