首先下载sqlite-netFx45-setup-bundle-x86-2012-1.0.84.0.rar并安装。
添加ado.net实体数据模型。
class="alt"> 1: //增加
2: money_used addUserd = new money_used();
3: addUserd.C_id = dbContext.money_used.Max(m => m.C_id) + 1;
4: addUserd.consume_type_id = 1;
5: addUserd.user_id = 1;
6: addUserd.money = 120;
7: addUserd.remark = "通过sqlite to linq 添加";
8: addUserd.picture = "通过slqite to linq 添加";
9: addUserd.created = DateTime.Now;
10: addUserd.is_deleted = false;
11: dbContext.money_used.Add(addUserd);
12: dbContext.SaveChanges();
这里有个问题,自增列不知道该如何处理。
1: //编辑
2: money_used editUserd = dbContext.money_used.FirstOrDefault(d => d.C_id == addUserd.C_id);
3: editUserd.remark = "修噶了";
4: dbContext.SaveChanges();
1: //删除
2: money_used delUserd = dbContext.money_used.FirstOrDefault(d => d.C_id == 0);
3: if (delUserd != null)
4: {
5: dbContext.money_used.Remove(delUserd);
6: dbContext.SaveChanges();
7: }
1: //查询
2: var source = from a in dbContext.money_used
3: select a;
4: foreach (var item in source)
5: {
6: Console.WriteLine(item.money + " " + item.picture);
7: }