3. Persist data in my WP 8.1 (Silverlight) app
Local database (SQLCE) saves the day
Store relational data
Sits in app’s local folder
Use LINQ TO SQL for
CREATE
RETRIEVE
UPDATE
DELETE
5. Third party database support!
SQLite for Windows Phone 8.1
World’s most popular database
Used in other OS too
Fast & Reliable
Support for multiple tables, triggers, views, indices
Follow ACID rules
6. What you need to
know when using
database in WP 8.1
(Silverlight)
7. Your database is in your code
DataContext
Act as a proxy, object that represents the database.
Table objects, represents a table in the database.
Made up of entities
Entity is a “plain old CLR object” (POCO) with attributes.
8. Behind the scene!
BlogId BlogName
Value Value
Blogs Table
PostId PostName
Value Value
Posts Table
BlogPostDatacontext
9. Play with data in OOP manners
LINQ TO SQL
ORM capabilities
Use LINQ to speak with the database
Translate LINQ to Transact-SQL and query the
database
Took the results and translate it again to LINQ
10. How it really works!
DataContext and Local database relation
Data Context Local Database
LINQ TO SQL
RUNTIME
11. Define who goes where!
LINQ to SQL mapping attributes
Specify database-specific features such as tables,
columns, primary keys, and indexes.
DatabaseAttribute (Name)
TableAttribute (Name)
ColumnAttribute (AutoSync, IsForeignKey, DbType, IsVersion)
AssociationAttribute (IsForeignKey, DeleteRule)
DataAttribute (Storage)
12. Teach LINQ TO SQL what to do
PostId (Pk) PostContent
Value (NOT NULL)
(AUTOINCREMENT)
(INT)
Value
Post Table
13. Association (1 to many)
PostId (Pk) PostContent BlogId
Value (NOT NULL)
(AUTOINCREMENT)
(INT)
Value value
BlogId (Pk) BlogName
Value (NOT NULL)
(AUTOINCREMENT)
(INT)
Value
Foreign Key
Post table
Blog table 1
M