This is the sixth article in the "Windows Phone Mango Local Database (SQLCE)" series. To get you started using the database in Windows Phone Mango, this series of short film articles will cover all the knowledge you need to know. I'll talk about using [Index] attribute on the Windows Phone Mango Local database.
first and foremost, the basic database functionality on Windows Phone 7.1 is an implementation of the SQL compact about Mango. You will use LINQ to SQL to access the data stored on the database.
Note : [Index] attribute in:Namespace:Microsoft.Phone.Data.Linq.MappingAssembly:System.Data.Linq (in System.Data.Linq.dll)1. [Index] What is attribute?fundamentally, [index] attribute specifies an additional index to the table on the local database. Write to the table level, specifying additional indexes on the table. Each index can overwrite one or more columns.
Note : [Index] attribute is typically used internally by the database engine. This means that, in addition to defining the index, you don't need to write LINQ to SQL queries or do something different to use the index. 2. Why to use [Index] attributeIf you use the "where" clause, the "by" clause, or the "join" clause in a LINQ query, the index on the appropriate column can greatly improve performance.
Note :[Index] attribute is typically used internally by the database engine 3. How to use [Index] attributeThe Index attribute has several important properties:
- 1. Columns: Gets or sets the column on which the index is based
- 2, IsUnique: Gets or sets a value that indicates whether the index is unique, and the unique index does not allow any two rows to have the same index key value
- 3. Name: Gets or sets the name of the index
Example 1:
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 }
Sample query (note: Your LINQ to SQL query looks like it is querying in the same way without using any indexes, but improves performance)
where p.name ="Londonselect P;
This article I talked about using [Index] attribute in the Windows Phone Mango Local database. Keep your eye on the next article.