Windows phone Local Database (SQLCE): 11, querying the Database using LINQ (translation)

Source: Internet
Author: User

This is the 11th 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 how to use LINQ to query the database in the Windows Phone Mango Local database.

1, database query is whaton the Windows Phone, language-Integrated query (LINQ) is used as a query database. LINQ is often used to represent a connection between an object and the actual data. Queries in LINQ to SQL use the same syntax as LINQ queries. because in LINQ to SQL queries, object references are mapped to records in the database. LINQ to SQL differs from queries that are executed by other LINQ technologies. In the application layer, a typical LINQ query is executed in memory. including LINQ to SQL, using runtime's object-relational capabilities, each LINQ query is translated into Transact-SQL and executed directly in the database, which can improve the performance of a query such as querying some records from a large database. Reference : You can take a look at the MSDN documentation http://msdn.microsoft.com/zh-cn/library/hh202861 (v=vs.92). aspxYou can also look at the second article in this series2. How to select datain the following example, the LINQ to SQL query, a DataContext object called "Countrydatacontext", is placed in the IList collection of the country class named "Countrylist". Note : In the following example, we will use the "Countrydatacontext" DataContext, which has been explained in previous articles. Example 1: Select All country records from the database
1Private ilist<country>Getcountries ()2{3 Ilist<country> countrylist =Null; 4 using (Countrydatacontext context = new Countrydatacontext (ConnectionString))  5  {from c in context. Countries select C; 7 Countrylist = query. ToList (); } 9 10 return Countrylist;                 

Example 2: Select All country records from the database whose names begin with "U"

1Private ilist<country>Getcountriesstartingwithu ()2{3 Ilist<country> countrylist =Null;4using (countrydatacontext context =NewCountrydatacontext (ConnectionString))5{6 iqueryable<country> query = 7 from c in context. Countries  8 where c.name.startswith ( "u )  9 select C; query. ToList (); 11 }12 13 return Countrylist;                 

This article I talked about in Windows Phone Mango using LINQ to query the 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.