Windows Phone本機資料庫(SQLCE):14、刪除資料(翻譯)

來源:互聯網
上載者:User

    一隻大菜鳥,最近要學習windows phone資料庫相關的知識,找到了一些比較簡短的教程進行學習,由於是英文的,順便給翻譯了。本身英語水平就不好,估計文中有不少錯誤,如果有不幸讀到的童鞋請保持對翻譯品質的質疑,多多指教。

    這是原文地址:http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--How-to-Delete-data本文如下:    這是“windows phone mango本機資料庫(sqlce)”系列短片文章的最後一篇第十四篇。 為了讓你開始在Windows Phone Mango中使用資料庫,這一系列短片文章將覆蓋所有你需要知道的知識點。我將談談在windows phone mango本機資料庫裡怎麼刪除資料。

    從資料庫裡刪除資料是一個三個步驟的過程。首先,從資料庫裡查詢要刪除的對象,然後,根據你要刪除的一個或多個對象,調用DeleteOnSubmit方法或者DeleteAllOnSubmit 方法刪除,分別使這些對象處於刪除狀態,最後調用SubmitChanges 方法儲存更改到本機資料庫。  注釋:直到SubmitChanges 方法被調用資料才會被刪除。 參考:你可以看看MSDN文檔:http://msdn.microsoft.com/zh-cn/library/hh202860(v=vs.92).aspx 1、怎麼刪除資料在開始之前,假設我們有下面兩張表的資料庫結構:Country和City

DataContext如下所示:

 1 public class CountryDataContext : DataContext 2  { 3      public CountryDataContext(string connectionString) 4          : base(connectionString) 5      { 6      } 7     8      public Table<Country> Countries 9      {10          get11          {12              return this.GetTable<Country>();13          }14      }15    16      public Table<City> Cities17      {18          get19          {20              return this.GetTable<City>();21          }22      }23  }
下面的程式碼範例示範了幾個過程:1、建立DataContext2、尋找要被刪除的目標“City”3、從DataContext刪除City4、調用SubmitChanges方法儲存更改
 1 private void DeleteCity() 2  { 3      using (CountryDataContext context = new CountryDataContext(ConnectionString)) 4      { 5          // find a city to delete 6          IQueryable<City> cityQuery = from c in context.Cities where c.Name == "Madrid" select c; 7          City cityToDelete = cityQuery.FirstOrDefault(); 8             9          // delete city from the context10          context.Cities.DeleteOnSubmit(cityToDelete);11    12          // save changes to the database13          context.SubmitChanges();14      }15  }

    這篇文章我談論了在windows phone mango本機資料庫刪除資料。希望你能喜歡它們並找到有用的東西。

 

    這是原文地址:http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--How-to-Delete-data
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.