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.