首页 技术 正文
技术 2022年11月8日
0 收藏 360 点赞 1,872 浏览 1374 个字

这是“windows phone mango本地数据库(sqlce)”系列短片文章的第六篇。 为了让你开始在Windows Phone Mango中使用数据库,这一系列短片文章将覆盖所有你需要知道的知识点。 我将谈谈在windows phone mango本地数据库时使用[Index] attribute。

   首先、要说到的是,windows phone 7.1上基本的数据库功能是SQL Compact关于Mango的一个实现。你将使用linq to sql访问存储在数据库上的数据。  注释:[Index] attribute在:Namespace:Microsoft.Phone.Data.Linq.MappingAssembly: System.Data.Linq (in System.Data.Linq.dll)  

1、[Index] attribute是什么

   从根本上说,[Index] attribute指定一个额外的索引到本地数据库的表上。写到表级别上,在表上指定额外的索引。每一个索引可以覆盖一个到多个列。注释:[Index] attribute通常被数据库引擎在内部使用。这意味着,除了定义索引之外,你不需要写LINQ to SQL查询或者为了使用索引而做一些其他不同的事情。 

2、为什么要使用[Index] attribute

   如果你在LINQ查询中使用“where”子句、“orderby”子句或者“join”子句,在适当的列上的索引能极大地提高性能。注释:[Index] attribute通常被数据库引擎在内部使用 

3、怎么使用[Index] attribute

   Index attribute有下面几个重要属性:

  • 1、Columns:获取或设置索引基于的列
  • 2、IsUnique:获取或设置一个值,这个值表明这个索引是否是唯一的,唯一索引 不允许任意两行具有相同的索引键值
  • 3、Name:获取或设置索引的名字

 示例1:Windows Phone本地数据库(SQLCE):6、[Index] attribute(翻译)(转)

 1 [Index(Columns = "Name", IsUnique = true, Name= "city_Name")]
2 [Table]
3 public class City
4 {
5 private Nullable<int> countryID;
6
7 [Column(IsPrimaryKey = true, IsDbGenerated = true)]
8 public int ID
9 {
10 get;
11 set;
12 }
13
14 [Column(CanBeNull = false)]
15 public string Name
16 {
17 get;
18 set;
19 }
20
21 [Column(Storage = "countryID", DbType = "Int")]
22 public int? CountryID
23 {
24 get
25 {
26 return this.countryID;
27 }
28 set
29 {
30 this.countryID = value;
31 }
32 }
33 //...
34 }

Windows Phone本地数据库(SQLCE):6、[Index] attribute(翻译)(转)

示例查询(注释:你的LINQ to SQL查询看起来像是以同样的而不使用任何索引方式进行查询,但提高了性能)

1 var query = from c in context.City where p.Name ="London" select p;

这篇文章我谈了有关在windows phone mango本地数据库中使用[Index] attribute。请继续关注接下来的文章。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295