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 supported ded 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/embeddedRelationalDatabase Management System (rdb ms). Local databases are very suitable for scenarios where you have related entities for example: MERs and orders.
The following scenarios are perfect for local database usage:
- Relatively specified 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 saved med efficiently and quickly
- Allows only data that is necessary at a participant 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 toSystem. Data. LINQAssembly 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 locking ing 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"Windows Phone mango local database (SQL CE)"Series of articles. Stay tuned for the rest of the posts.