基于tim heuer最新提供的方法
他相关post的地址: http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx
以下是实践过程:
step 1:创建一个metro工程
step 2:在工具,选择扩展与更新中,选择联机(online),在搜索框内输入sqlite
将会发现一个叫做sqlite for window runtime的玩意儿,点击安装
step 3:在引用中,选择windows,扩展,把Mircosoft visual c++ runtime package以及sqlite for windows runtime二者勾选上
勾选Mircosoft visual c++ runtime package是作者推荐,据说这样子才不会出问题。有兴趣的可以深究下原因。
step 4: 点选解决方案,选择属性,配置属性,将平台选择为对应的平台,暂时不支持any cpu
step 5: 点击工程,选择管理nuget包,在联机中搜索sqlite-net,点击安装
安装成功后会生成两个文件:SQLite.cs与SQLiteAsync
至此,就完成了sqlite的安装,下面提供一段简陋的测试代码:
01 |
using SQLite; |
02 |
03 |
public MainPage() |
04 |
{ |
05 |
this.InitializeComponent(); |
06 |
test(); |
07 |
} |
08 |
09 |
private async void test() |
10 |
{ |
11 |
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("people"); |
12 |
await conn.CreateTableAsync<Person>(); |
13 |
14 |
} |
15 |
16 |
Person.cs: |
17 |
18 |
public class Person |
19 |
{ |
20 |
[PrimaryKey, AutoIncrement] |
21 |
public int Id { get; set; } |
22 |
23 |
[MaxLength(30)] |
24 |
public string Name { get; set; } |
25 |
26 |
[MaxLength(30)] |
27 |
public string Surname { get; set; } |
28 |
29 |
本文引用http://www.devdiv.com/metro%E4%B8%ADsqlite%E5%AE%89%E8%A3%85%E5%BF%83%E5%BE%97-weblog-252306-13068.html |
原文:http://www.cnblogs.com/fengzhengfly/p/4369511.html