使用MvvmCross,复制预填充SQLite数据库的首选方法是什么
我正在修改N-10-KittensDb样本解决方案.
我看到如何创建SQLite数据库,但我希望使用现有的数据库.我猜我需要将数据库复制到正确的UI数据文件夹.也许它是在Core项目中完成的?如果是这样,如何将正确的路径注入到正在运行的Exec中?因为Core可以在许多UI中使用?调用什么方法来查看数据库是否存在或需要复制? 来自DataService的示例: public DataService(ISQLiteConnectionFactory factory) { const string file = "Cats.sldb"; var connection = factory.Create(file); connection.CreateTable<Kitten>(); } 我相信Android vs Phone vs Touch vs Wpf的路径不同? 请指导我使用Cirrious.MvvmCross.Plugins.Sqlite for Phone或Wpf的示例代码. 谢谢 public ISQLiteConnection Create(string address) { var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); return new SQLiteConnection(Path.Combine(path,address)); } 从https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/Sqlite/Cirrious.MvvmCross.Plugins.Sqlite.Touch/MvxTouchSQLiteConnectionFactory.cs#L18 为了读/写文件,MvvmCross确实捆绑了一个File插件 – 这也默认在平台特定位置运行 – 但两者可能不完全匹配 – 例如看到: protected override string FullPath(string path) { if (path.StartsWith(ResScheme)) return path.Substring(ResScheme.Length); return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),path); } 从https://github.com/slodge/MvvmCross/blob/v3/Plugins/Cirrious/File/Cirrious.MvvmCross.Plugins.File.Touch/MvxTouchFileStore.cs#L22开始 由于这种不匹配,为了跨平台共享相同的特定于数据库的复制代码,您可能会发现在每个平台上注入自己的平台特定副本更容易 – 有关注入平台特定服务的更多信息,请参阅http://slodge.blogspot.co.uk/2013/06/n31-injection-platform-specific.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |