Windows Phone local database (sqlce): 4. [column] 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--Column-attribute

The text is as follows:

This is a short film in the "Windows Phone mango local database (sqlce)" series.Article. 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 [column] attribute in the Windows Phone mango local database.

First, it should be noted that the database function on 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. 1. What is [column] attribute? In addition to associating a class to a table (explained in the previous article), you need to indicate each field or attribute that you intend to associate with a data table column. To solve this problem, [column] attribute is provided for LINQ to SQL. You canPreciselyUse a custom field or attribute to map to a data table column. An Attribute worth noting is isprimarykey. It tells the data table columns in the LINQ to SQL table to be part of the primary key. Reference: You can take a look at the msdn document http://msdn.microsoft.com/zh-cn/library/system.data.linq.mapping.columnattribute.aspx Only when the field and attribute are declared as column will be persisted or retrieved from the database. Others will be considered your applicationProgramThe short part of the logic. 2. How to use [column] attribute Note: 1. Use commas to separate multiple attributes. 2. You can only use column attribute in a class to mark it on [Table] attribute. (This sentence cannot be translated. The original Article is the column attribute must be used only in a class marked with the [Table] attribute .)
 1   [Table]  2   Public   Class  City  3   {  4   ...  5 [Column (isprimarykey = True  )] 6       Public   Int  ID  7   {  8           Get  ;  9           Set  ;  10 }

Example 1: column is the primary key

1[Column (isprimarykey =True, Isdbgenerated =True)]2 Public IntID3 {4Get;5Set;6}
Note:CodeIn the clip, in addition to the isprimarykey attribute, we can also set the isdbgenerated attribute to true. This indicates that the value of the column sqlce runtime should be automatically increased, which is useful most of the time. If you need it, you can certainly generate your own primary key value. In this case, you only need to set the isdbgenerated attribute to the default value or false. Example 2: column accepts null values
 
1[Column (canbenull =False)]2 Public StringName3 {4Get;5Set;6}

This article describes how to use [column] 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.