Windows phone Local Database (SQLCE): 4, [Column]attribute (translation)

Source: Internet
Author: User



This is the fourth 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 [Column] attribute on the Windows Phone Mango Local database.


first of all, the 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. 1. [Column] What is attribute?In addition to the association class to the table (as explained in the previous article), you need to indicate each field or property that you intend to associate to the data table column. To do this, LINQ to SQL provides the [Column] attribute. column attribute's various properties, you can precisely use to customize the mapping between a field or a property and a data table column. One of the notable attributes is IsPrimaryKey. It tells the data table columns in the LINQ to SQL table to be part of the primary key. Reference : You can look at the MSDN documentation http://msdn.microsoft.com/zh-cn/library/ System.data.linq.mapping.columnattribute.aspx only fields and attributes declared as column are persisted or retrieved from the database. The rest will be considered a temporary part of your application logic. 2. How to use [Column] attribute notes:1. Use commas on attributes to separate multiple attributes2. You can use column attribute only in one class to mark [Table]attribute]. (This sentence is not very translatable, the original 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 int ID
3 {
4     get;
5     set;
6 }
Note: In addition to the IsPrimaryKey property, we can also set the IsDbGenerated property to true in the code snippet above. this tells the SQLCE runtime that the value on this column should automatically increase, which is useful for most of the time. You can, of course, generate the primary key value yourself if you need to. In this case, you only need to set the IsDbGenerated property to the default value or FALSE. example 2:column accept null values
 
1 [Column(CanBeNull = false)]
2 public string Name
3 {
4     get;
5     set;
6 }


This article I talked about using [Column] attribute in the Windows Phone Mango Local database. Keep your eye on the next article.


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.