Windows Phone本地数据库(SQLCE):8、DataContext(翻译)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第八篇。 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知识点。我将谈谈在windows phone mango本地数据库中使用DataContext的问题。
1、DataContext是什么
2、怎么创建DataContext

1 public class CountryDataContext : DataContext
2 {
3 public CountryDataContext(string connectionString)
4 : base(connectionString)
5 {
6 }
7
8 public Table<Country> Countries
9 {
10 get
11 {
12 return this.GetTable<Country>();
13 }
14 }
15
16 public Table<City> Cities
17 {
18 get
19 {
20 return this.GetTable<City>();
21 }
22 }
23 }

3、怎么使用DataContext

1 public MainPage()
2 {
3 InitializeComponent();
4
5 using (CountryDataContext context = new CountryDataContext(ConnectionString))
6 {
7
8 if (!context.DatabaseExists())
9 {
10 // create database if it does not exist
11 context.CreateDatabase();
12 }
13 }
14 }

现在你有context,并且数据库已经创建好了。你可以像示例里那样查询:
1 var query = from c in context.City where p.Name ="London" select p;
这篇文章我讨论了在windows phone mango 本地数据库中的DataContext,并且如何使用它们。请继续关注接下来的文章。
Windows Phone本地数据库(SQLCE):8、DataContext(翻译)的更多相关文章
- Windows Phone本地数据库(SQLCE):11、使用LINQ查询数据库(翻译) (转)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第十一篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的 ...
- Windows Phone本地数据库(SQLCE):2、LINQ to SQL(翻译)(转)
首先.要说到的是,windows phone 7.1上基本的数据库功能是SQL Compact关于Mango的一个实现,使用linq to sql访问存储在数据库上的数据. 1.LINQ to S ...
- Windows Phone本地数据库(SQLCE):1、介绍(翻译)(转)
一只大菜鸟,最近要学习windows phone数据库相关的知识,找到了一些比较简短的教程进行学习,由于是英文的,顺便给翻译了.本身英语水平就不好,估计文中有不少错误,如果有不幸读到的童鞋请保持对翻译 ...
- Windows Phone本地数据库(SQLCE):14、删除数据(翻译)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的最后一篇第十四篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需 ...
- Windows Phone本地数据库(SQLCE):13、更新数据(翻译)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第十三篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的 ...
- Windows Phone本地数据库(SQLCE):12、插入数据(翻译)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第十二篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的 ...
- Windows Phone本地数据库(SQLCE):10、创建数据库(翻译) (转)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第十篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...
- Windows Phone本地数据库(SQLCE):7、Database mapping(翻译)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第七篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...
- Windows Phone本地数据库(SQLCE):4、[Column]attribute(翻译) (转)
这是“windows phone mango本地数据库(sqlce)”系列短片文章的第四篇. 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知 ...
随机推荐
- JavaScript——创建对象
<script type="text/javascript"> //声明变量的首字母是小写 //1.对象字面量 /*var person = { name:" ...
- Maven打包Swing程序
有两个maven工程:见下. 第二个工程依赖第一个工程,第二个工程是swing,两个工程都需要链接数据库. 打包步骤: 1.主要第二个工程主类,run as --->java applicati ...
- poj1273
赤裸裸的最大流 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstr ...
- 11 Go 1.11 Release Notes
Go 1.11 Release Notes Introduction to Go 1.11 Changes to the language Ports WebAssembly RISC-V GOARC ...
- Oracle优化技巧
现观察线上系统运行发现,线上某些业务查询存在等待时间长问题,后核查发现,部分问题出现在对数据库操作上Cost大部分时间,后根据网上各位前辈提供的优化技巧解决大部分问题,现写下本篇文章,一来巩固加深自己 ...
- Selenium Books
Recently, some of my projects rely heavily upon tests with selenium. Some books about selenium are c ...
- ansible学习
声明:本博客内容是根据惨绿少年内容实践随笔,地址:http://www.cnblogs.com/clsn/p/7743792.html#comment_form 1.ansible介绍 Ansible ...
- 入门NodeJS
入门NodeJS https://www.cnblogs.com/dotnetcrazy/p/10118756.html NodeJS 1.环境配置 之前讲ES6的时候有提过一部分Node的知识,简单 ...
- 【LOJ】 #2547. 「JSOI2018」防御网络
题解 如果只是一棵树的话,那么就枚举每条边,分成两部分大小为\(a\)和\(b\) 那么这条边被统计的方案数是\((2^a - 1)(2^b - 1)\) 如果是一个环的话,我们枚举环上至少有\(N ...
- ubuntun 18.04 desktop安装jupyter-notebook
在ubuntu18.04要安装jupyter-notebook,当然前提是先安装python,然后按如下步骤安装jupyter-notebook,现在记录如下: 1.sudo apt-get upda ...