我正在尝试使用最新版本的 sqlite-net-pcl nuget 包创建一个表
var db = new SQLiteAsyncConnection("data.db");
await db.CreateTableAsync<Site>();
Run Code Online (Sandbox Code Playgroud)
CreateTableAsync 调用引发以下异常:
System.MissingMethodException: '方法未找到:'System.String SQLitePCL.raw.sqlite3_column_name(SQLitePCL.sqlite3_stmt, Int32)'。'
这是站点类
public class Site
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public String Name;
public String PriceCssSelector;
public String URLRegex;
public Site()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试降级到 sqlite-net-pcl 包的最新稳定版本。
当我调试 UWP 项目时,出现以下错误:
System.IO.FileNotFoundException: '无法加载文件或程序集 'e_sqlite3,Culture=neutral,PublicKeyToken=null'。该系统找不到指定的文件。'
错误发生在这一行:
Xamarin.Forms.Forms.Init(e);
从以下代码块:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously …Run Code Online (Sandbox Code Playgroud) 我们有一个Xamarin.Forms项目,需要使用sqlite本地数据库来存储日期。来自不同PC的不同开发人员使用EF Core的sqlite库进行设置(vs 2019)。最初,它与Database.EnsureCreated()功能一起使用,后来与ef core的迁移一起使用。一切都进行了一个多月。
上周,由于sqlite出现错误,Android应用突然无法在任何人的PC上启动。它显示以下错误:
致命信号11(SIGSEGV),代码1(SEGV_MAPERR)
我花了一段时间尝试各种修复和回滚,认为这是代码的问题。其中包括以下内容:
在尝试了上述修复程序和其他修复程序之后,终于在上周五(在所有PC上)升级了Java和android SDK的版本。此修复程序奏效后,当天一切都会顺利进行。在星期二,问题再次出现(没有库更新或代码更改)。更深入地了解EF Cores日志记录表明,它在尝试连接到数据库时崩溃。
该问题可以在android设备上复制,但不能在模拟器上复制。我不确定我们是否需要请求android中的一些新权限。
我终于用sqlite设置创建了一个新的xamarin表单项目。我使用了pcl库和ef核心。我仍然发现相同的错误。
这是复制问题的git枢纽https://github.com/neville-nazerane/xamarin-site
更新资料
只是我注意到的东西。早些时候,我的数据库文件名为“ main.db”。现在,无论我将该文件名更改为什么或更改任何变量。它在日志中始终将数据库名称显示为“ main”。不知道更改数据库名称是否可以解决该问题。但是,从未找到更改此数据库名称的方法。我尝试了不同的连接字符串,它只是说“数据库”和“ db”是未知键
更新资料
复制步骤:
using (var db = new AppDbContext())
{
db.Add(new Person {
Age = 55,
Name = "Neville"
});
db.SaveChanges();
Person[] alldata = db.People.ToArray();
}
Run Code Online (Sandbox Code Playgroud)
的定义Person和AppDbContext是相当明显的。因此,本着不让问题太长的精神,我不在此发布。但是,如果需要,我也可以发布它们。
xamarin.android xamarin.forms entity-framework-core sqlite-net-pcl
我正在尝试实现SQLite的基本用法。我有一个Button和一个EditText。我要存储的内容EditText OnClick。
我正在关注:https : //developer.xamarin.com/guides/android/application_fundamentals/data/part_3_using_sqlite_orm/
和https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/databases/
我无法通过下面的启动代码,而没有得到随后的错误: var db = new SQLiteConnection (dbPath);
错误:
“ SQLite.SQLiteConnection”的类型初始值设定项引发了异常。
内部异常:
System.Exception:这是“诱饵”。您可能需要将SQLitePCLRaw.bundle_ * nuget包之一添加到平台项目中。
在SQLitePCL.Batteries_V2.Init()[0x00000]在<9baed10c674b49e0b16322f238b8ecc1>:0在/Users/vagrant/git/src/SQLite.cs:169的SQLite.SQLiteConnection..cctor()[0x00000]处
我已经在PCL和Android项目上都安装了NuGet软件包。我看到安装了以下软件包:
SQLitePCLRaw.provider.e_sqlite3.android
SQLitePCLRaw.lib.e_sqlite3.android
Run Code Online (Sandbox Code Playgroud)
我试过安装:
SQLitePCLRaw.bundle_e_sqlite3
Run Code Online (Sandbox Code Playgroud)
如前所述,代码是可能的最基本实现:
try
{
string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TestDB-DEV.db3");
var db = new SQLiteConnection(dbPath);
db.CreateTable<PersonName>();
}
Run Code Online (Sandbox Code Playgroud)
我花了几天时间,尝试了许多资源,例如:https : //forums.xamarin.com/discussion/87289/sqlite-net-pcl-bait-issue,但最终没有成功。
不幸的是,我所见过的唯一答案就是胡说八道,例如“它能正常工作”,“不确定我做了什么”,“清理/重建”,例如以前的链接,其他诸如Xamarin SQLite之类的SO帖子“这是'诱饵'”。
这是我package.config的Android项目:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="sqlite-net-pcl" version="1.4.118" targetFramework="monoandroid60" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.5" targetFramework="monoandroid60" />
<package id="SQLitePCLRaw.core" version="1.1.5" targetFramework="monoandroid60" …Run Code Online (Sandbox Code Playgroud) OS/X Mac Xamarin Forms Visual Studio Pro 2017
我正在尝试学习 Mosh Hamedani 关于 Xamarin 表单的精彩课程。我尝试编写第 89 讲中的相同代码:
var connection = DependencyService.Get<ISQLiteDb>().GetConnection();
connection.CreateTablesAsync<Recipe>();
Run Code Online (Sandbox Code Playgroud)
但是...我收到错误:
使用通用方法... CreateTablesAsync < t1 , t2 > () 需要 2 个类型参数
但即使是Xamarin 文档也没有这么说!它仅显示您希望将表创建为的表类类型的一种类型参数。
我该如何解决这个问题?
我想对保存在 SQLite 数据库中的日历条目进行排序,以便在列表视图中显示它们。如何使用 SQLite-net-plc 订购它们?
我以为我可以写:.OrderBy<CalendarEntryStartDate>但它不起作用,我尝试使用 SQLite 命令,但在使用它们时遇到了一些麻烦,因为我对 m.db 感到困惑。
using System;
using SQLite;
namespace Stundenplan.Models
{
public class CalendarEntry
{
[PrimaryKey, AutoIncrement]
public int CalendarEntryId { get; set; }
public string CalendarEntryTitle { get; set; }
public string CalendarEntryDescription { get; set; }
[Column("StatDate")]
public DateTime CalendarEntryStartDate { get; set; }
public DateTime CalendarEntryEndDate { get; set; }
public TimeSpan CalendarEntrySpan { get; set; }
public string CalendarEntryParticipants { get; set; }
public string CalendarEntrytLocation { get; …Run Code Online (Sandbox Code Playgroud) 当Xamarin.Forms项目中出现页面时,我有一个AppearingCommand调用,该页面最终执行以下sqlite-net-pcl行:(我已经有一种应对加载时间的机制)
AppearingCommand = new Command( async() => {
//...
var data = await db.Table<PlantCategory>().ToListAsync();
//...
}
Run Code Online (Sandbox Code Playgroud)
我想将此方法移到构造函数中,但我不能这样做,因为如果同步执行它会挂起:
ctor() {
//...
var data = db.Table<PlantCategory>().ToListAsync().Result;
//...
}
Run Code Online (Sandbox Code Playgroud)
该行永远不会返回(我猜是由于死锁或其他原因)。如果要在构造函数中执行此行,我还有什么其他选择?