Windows phone Local Database (SQLCE): 14, deleting data (translation)

Source: Internet
Author: User

This is the 14th installment of the "Windows Phone Mango Local Database (SQLCE)" series short story. 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 delete data in the Windows Phone Mango Local database.

deleting data from a database is a three-step process. First, query the object to be deleted from the database, and then, depending on the object or objects you want to delete, call the DeleteOnSubmit method or the Deleteallonsubmit method to delete the objects, respectively, so that they are in the delete state, and finally call SubmitChanges method to save changes to the local database. Note : Data will not be deleted until the SubmitChanges method is called. Reference: You can look at the MSDN documentation: http://msdn.microsoft.com/zh-cn/library/hh202860 (v=vs.92). aspx1. How to delete databefore we start, let's say we have the database structure of the following two tables: Country and City

The DataContext is as follows:

1PublicClassCountrydatacontext:datacontext2{3Public Countrydatacontext (StringconnectionString)4:Base(connectionString)5{6}78Public table<country>Countries9{10Get11{12ReturnThis. Gettable<country>();13 }14 }15 16 public Table <city> Cities17  {18 get19  {20 return this. Gettable<city> (); }22 }23}                 
The following code example demonstrates several procedures:1. Create DataContext2. Find the target "city" to be deleted3. Delete City from DataContext4. Call the SubmitChanges method to save the changes
1PrivatevoidDeletecity ()2{3using (countrydatacontext context =NewCountrydatacontext (ConnectionString))4{5//Find a city to delete6 iqueryable<city> cityquery =From cIn context. Citieswhere c.name = ="Madrid "select C; 7 city citytodelete = Cityquery.firstordefault ();  8 Span style= "color: #008080;" > 9 // Delete city from the Context10  context. Cities.deleteonsubmit (Citytodelete); 11 12 // save changes to the Database13  context. SubmitChanges (); 14 }15}     

This article I talked about deleting data in the Windows Phone Mango Local database. I hope you can enjoy them and find something useful.

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.