Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQLite中存储应用程序设置_Sqlite_Xamarin_Mvvmcross - Fatal编程技术网

在SQLite中存储应用程序设置

在SQLite中存储应用程序设置,sqlite,xamarin,mvvmcross,Sqlite,Xamarin,Mvvmcross,我正在开发我的第一个MvvmCross应用程序。我正在尝试用SQLite存储应用程序设置,但我遇到了一些异常,我担心我遗漏了一些东西。希望有人能指导我使用MvvmCross SQLite 在应用程序启动时,我想从SQLite检索应用程序设置。我尝试的是: var connection=factory.Create(“myAppDB”); 返回连接。Get(1) 在这一点上,我得到一个异常,因为第一次启动应用程序时,AppSettings表不存在 如果我尝试使用以下内容创建表: var conne

我正在开发我的第一个MvvmCross应用程序。我正在尝试用SQLite存储应用程序设置,但我遇到了一些异常,我担心我遗漏了一些东西。希望有人能指导我使用MvvmCross SQLite

在应用程序启动时,我想从SQLite检索应用程序设置。我尝试的是: var connection=factory.Create(“myAppDB”); 返回连接。Get(1)

在这一点上,我得到一个异常,因为第一次启动应用程序时,AppSettings表不存在

如果我尝试使用以下内容创建表:

var connection = factory.Create("myAppDB");
connection.CreateTable<AppSettings>();
var connection=factory.Create(“myAppDB”);
connection.CreateTable();
我得到了下一个例外: “System.NotSupportedException:不了解Cirrial.MvvmCross.ViewModels.MvxRequestedBy”

有什么帮助吗?谢谢

代码看起来不错:

 var connection = factory.Create("mydb.sq;");
 connection.CreateTable<TableType>();

我将很快发布一个完整的回购和N+1视频-同时,我在Evolve上做的演示正在进行-它在nuget软件包方面有点过时,但中的SQLite代码是最新的。

谢谢Stuart。异常与AppSettings类型相关。AppSettings继承自MvxViewModel。我已经创建了一个新的AppSettingsEntityClass普通类,该类仅使用CLR类型的属性来存储所需的信息,现在工作正常。如果您的appsettings中需要inpc,请尝试mvxnotifypropertychanged基类
public class Kitten
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string Name { get; set; }
    public int Price { get; set; }
    public string ImageUrl { get; set; }
}

public class DataService
{
    private readonly ISQLiteConnection _connection;

    public DataService(ISQLiteConnectionFactory factory)
    {
        _connection = factory.Create("kittens.sql");
        _connection.CreateTable<Kitten>();
    }

    public List<Kitten> KittensMatching(string nameFilter)
    {
        return _connection.Table<Kitten>()
                    .OrderBy(x => x.Price)
                    .Where(x => x.Name.Contains(nameFilter))
                    .ToList();
    }

    // other db methods
}