使用MvvmCross,复制预填充的SQLite数据库的首选方法是什么 [英] With MvvmCross what is the preferred way to copy a prefilled SQLite Database

查看:87
本文介绍了使用MvvmCross,复制预填充的SQLite数据库的首选方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改N-10-KittensDb示例解决方案. 我看到了如何创建SQLite数据库,但是我希望使用现有的数据库.我猜想我需要将数据库复制到正确的UI数据文件夹中.也许是在核心项目中完成的?如果是这样,如何将正确的路径注入运行中的Exec?可以在许多UI中使用Core吗?调用哪种方法来查看数据库是否存在或需要复制?

I am modifying the N-10-KittensDb sample solution. I See how to create a SQLite database, but I wish to use an existing database. I am guessing that I need to copy the database to the proper UI data folder. Maybe it is done within the Core project? And if so how is the correct path injected into the running Exec? As the Core can be used across many UI's? What method is called to see if the database exists or needs to be copied?

DataService的示例:

Sample from DataService:

public DataService(ISQLiteConnectionFactory factory)
{
    const string file = "Cats.sldb";
    var connection = factory.Create(file);
    connection.CreateTable<Kitten>();
}

我相信Android,电话,触摸,Wpf的路径是不同的吗?

I believe the paths are different for Android vs Phone vs Touch vs Wpf?

请将我定向到使用用于电话或Wpf的Cirrious.MvvmCross.Plugins.Sqlite的示例代码.

Please direct me to a sample piece of code that uses the Cirrious.MvvmCross.Plugins.Sqlite for Phone or Wpf.

谢谢 丹

推荐答案

每个平台默认情况下都会在适合该平台的文件夹位置中创建一个数据库-例如触摸用途:

Each platform by default creates a database in a folder location appropriate for the platform - e.g. Touch uses:

    public ISQLiteConnection Create(string address)
    {
        var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        return new SQLiteConnection(Path.Combine(path, address));
    }

来自要读取/写入文件,MvvmCross会捆绑一个File插件-默认情况下,该插件也可在特定于平台的位置运行-但两者可能并不完全匹配-例如看到:

To read/write files, MvvmCross does bundle a File plugin - this also operates by default in platform specific locations - but the two may not match perfectly - e.g. see:

    protected override string FullPath(string path)
    {
        if (path.StartsWith(ResScheme))
            return path.Substring(ResScheme.Length);

        return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), path);
    }

来自由于这种不匹配,为了在平台之间共享相同的特定于数据库的复制代码,您可能会发现在每个平台上注入自己的特定于平台的副本会更容易-有关注入特定于平台的服务的更多信息,请参见 http://slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html

Because of this mismatch, in order to share the same database-specific copy code across platforms you may find it easier to just inject your own platform specific copy on each platform - for more on injecting platform specific services, see http://slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html

这篇关于使用MvvmCross,复制预填充的SQLite数据库的首选方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆