Windows Phone Mango Local Database(SQL CE): Introduction

來源:互聯網
上載者:User

by WindowsPhoneGeek

I am starting a new "Windows Phone Mango Local Database(SQL CE)" series of short posts that will cover all you need to know in order  to get started using a Local Database in Windows Phone 7.1 Mango.  Here is what is included in this series:

  • Windows Phone Mango Local Database(SQL CE): Introduction
  • Windows Phone Mango Local Database(SQL CE): Linq to SQL
  • Windows Phone Mango Local Database(SQL CE): [Table] attribute
  • Windows Phone Mango Local Database(SQL CE): [Column] attribute
  • Windows Phone Mango Local Database(SQL CE): [Association] attribute
  • Windows Phone Mango Local Database(SQL CE): [Index] attribute
  • Windows Phone Mango Local Database(SQL CE): Database mapping
  • Windows Phone Mango Local Database(SQL CE): DataContext
  • Windows Phone Mango Local Database(SQL CE): Connection Strings
  • Windows Phone Mango Local Database(SQL CE): Creating the Database
  • Windows Phone Mango Local Database(SQL CE): Database Queries with LINQ
  • Windows Phone Mango Local Database(SQL CE): How to Insert data
  • Windows Phone Mango Local Database(SQL CE): How to Update data
  • Windows Phone Mango Local Database(SQL CE): How to Delete data

This is the first post so I am going to give a brief explanation of what a Local Database is and what else you need to know before getting started using SQL CE in  Windows Phone 7.1 Mango applications.

What is Local Database?

To begin with, lets first mention that with Windows Phone 7.1 Mango, you can now store relational data in a Local Database stored in your application's Isolated Storage. In Windows Phone all applications are "isolated" from each other, which means that one application can access only its own Isolated Storage. I.e one database can be used only from one application and can not be shared between several applications.

Local database in Windows Phone 7.1 is an implementation of SQL Compact for Mango. It is an in memory/embedded relationaldatabase management system (RDB MS). Local databases are very suitable for scenarios where you have related entities for example:  Customers and Orders.

The following scenarios are perfect for local database usage:

  • Relatively many related Tables/entities containing a moderate amount of records
  • A few tables containing large amounts of records/data
  • Local cache of data that comes from the cloud

A local database offers the following advantages:

  • the ability to make complex queries to the database which are performed efficiently and quickly
  • allows only data that is necessary at a particular moment to be loaded in memory
  • you can do all operations like : adding , removing, inserting, deleting, etc and all this operations are handled efficiently by the SQL Compact runtime.

Here is the Process that you need to follow in order to use a Local Database in Windows Phone:

  • 1. Implement all database classes: tables, columns, relations, datacontext, etc.
  • 2. Create a new database (,sdf) file in Isolated Storage(by default the database is empty).
  • 3. Populate the database stored in the Isolated Storage with data

8 Things you need to know about SQL CE before you begin

  • LINQ to SQL is used as the ORM engine
  • Database files are stored in Isolated Storage
  • LINQ is used to query data, T-SQL queries are not supported
  • There is no need to distribute assemblies that will increase the application size, with Windows Phone Mango the Local Database support is part of the framework.
  • A reference to the System.Data.Linq assembly must be added to the project
  • A special format of the connection string must be used like for example: 
    "Data Source='isostore:/DIRECTORY/FILE.sdf'";
  • The code-first approach to defining the database schema is preferred in this version of Windows Phone 7.1 Mango. I.e. at the moment there is no visual designer that can help developers mapping and configuring their classes to work with the database(so you have to write all classes on your own). However you can use tools like: Using SqlMetal to generate Windows Phone Mango Local Database classes
  • Minimum requirements: Visual Studio 2010 SP1 and Windows Phone 7.1 Mango Developer Tools

You can also take a look at the MSDN section: Local Database Overview for Windows Phone

That was the intro post of the "Windows Phone Mango Local Database(SQL CE)"  series of articles. Stay tuned for the rest of the posts.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.