Add an index to the Windows Phone 7 SqlCE Database

Source: Internet
Author: User

Wp7 can use SqlCE as a local database, so how to create a database index.

When a table is created and a primary key is specified, the database is set to an index by default. How can I manually set a column as an index?

After querying MSDN, we found that adding [Index] to define a column before the table class, but you must add the following two reference statements at the top of the code file:

using Microsoft.Phone.Data.Linq;
using Microsoft.Phone.Data.Linq.Mapping;

Common attributes of LINQ ing to SQL:

Attribute

Example

Description

TableAttribute

[Table]

Specify a class as the object class associated with the database table.

ColumnAttribute

[Column (IsPrimaryKey = true)]

Associate a class with columns in a database table. IsPrimaryKey specifies the primary key. By default, an index is created for it.

IndexAttribute

[Index (Columns = "Column1, Column2 DESC", IsUnique = true, Name = "MultiColumnIndex")]

Write Data at the table level, specifying other indexes on the table. Each index can cover one or more columns.

AssociationAttribute

[Association (Storage = "ThisEntityRefName", ThisKey = "ThisEntityID", OtherKey = "TargetEntityID")]

Specify the associated attributes, for example, the foreign key associated with the primary key.

Http://msdn.microsoft.com/zh-cn/library/hh202860 (v = vs.92). aspx

 

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.