Windows Phone local database (sqlce): 11. query the database using LINQ)

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 article address: Ghost. This is the first 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 how to query a database using LINQ in the Windows Phone mango local database.

1. What is database query on Windows Phone? Language integration query (LINQ) is used to query the database. LINQ is commonly used to indicate the connection between objects and actual data. The query in LINQ to SQL uses the same syntax as the query in LINQ. This is because the object reference is mapped to the records in the database in the LINQ to SQL query. Unlike the query executed by other LINQ technologies. In the application layer, a typical LINQ query is executed in the memory. Including LINQ to SQL, using the object relational capability of runtime, every LINQ query is translated into Transact-SQL and executed directly in the database, this improves the performance of a query, for example, querying some records from a large database. Reference: You can take a look at the msdn document http://msdn.microsoft.com/zh-cn/library/hh202861 (V = vs.92 ). aspx you can also look at Article 2 of this series. 2. How to Select data? In the following example, A datacontext object called "countrydatacontext" is queried using LINQ to SQL, the result is placed in the ilist set of the Country class named "countrylist. Note: In the following example, we will use the "countrydatacontext" datacontext, which has been explained in the previous article. Example 1: select all country records from the database
 1 private IList<Country> GetCountries() 2  { 3      IList<Country> countryList = null; 4      using (CountryDataContext context = new CountryDataContext(ConnectionString)) 5      { 6          IQueryable<Country> query = from c in context.Countries select c; 7          countryList = query.ToList(); 8      } 9    10      return countryList;11  }

Example 2: select all country records whose names start with "U" from the database

 1 private IList<Country> GetCountriesStartingWithU() 2  { 3      IList<Country> countryList = null; 4      using (CountryDataContext context = new CountryDataContext(ConnectionString)) 5      { 6          IQueryable<Country> query =  7              from c in context.Countries  8              where c.Name.StartsWith("U")  9              select c;10          countryList = query.ToList();11      }12   13      return countryList;14  }

In this article, I talked about how to query a database using LINQ in Windows Phone mango. Continue to pay attention to the following articles.

 

This is the original address: http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--Database-Queries-with-LINQ
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.