Windows Phone local database (sqlce): 6. [Index] attribute)

Source: Internet
Author: User

A newbie recently wants to learn about the Windows Phone database and find some short tutorials. Because it is in English, it is translated by the way. The English level is not good. It is estimated that there are many mistakes in the text. If you have any children's shoes that are unfortunately read, please keep in doubt about the translation quality and give me more advice.

This is the original address: http://www.windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--Index-attribute

The text is as follows:

This is the sixth article in the Windows Phone mango local database (sqlce) series. To get you started using databases in Windows Phone mango, this series of short clips will cover all the things you need to know. I will talk about using [Index] attribute in the Windows Phone mango local database.

First of all, it should be mentioned that the basic database function in Windows Phone 7.1 is an implementation of mango in SQL compact. You will access the data stored in the database using LINQ to SQL. Note: [Index] attribute in: namespace: Microsoft. phone. data. LINQ. mappingassembly: system. data. LINQ (in system. data. LINQ. DLL) 1. What is [Index] attribute? Basically, [Index] attribute specifies an additional index to a table in the local database. Write to the table level and specify additional indexes for the table. Each index can overwrite one or more columns. Note: [Index] attribute is usually used internally by the database engine. This means that, apart from defining indexes, you do not need to write a LINQ to SQL query or do something different to use indexes. 2. Why should we use [Index] attribute? If you use the WHERE clause, orderby clause, or join clause in a LINQ query, indexes on appropriate columns can greatly improve performance. Note: [Index] attribute is usually used internally by the database engine. 3. How to use [Index] attribute index attribute has the following important attributes:
  • 1. columns: Get or set the Column Based on the index
  • 2. isunique: gets or sets a value. This value indicates whether the index is unique. The unique index does not allow any two rows to have the same index key value.
  • 3. Name: gets or sets the index name.
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 Name16     {17         get;18         set;19     }20    21     [Column(Storage = "countryID", DbType = "Int")]22     public int? CountryID23     {24         get25         {26             return this.countryID;27         }28         set29         {30             this.countryID = value;31         }32     }33 //...34 }

Example query (Note: Your LINQ to SQL query looks like the same query without any index, but improves performance)

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

This article describes how to use [Index] attribute in the Windows Phone mango local database. Continue to pay attention to the following articles.

 

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.