play with windows phone local database

18
When database matters! Fiyaz Bin Hasan Former MSP (AUST) , NerdCats

Upload: fiyaz-hasan

Post on 22-Jan-2018

375 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Play With Windows Phone Local Database

When database matters!

Fiyaz Bin HasanFormer MSP (AUST) , NerdCats

Page 2: Play With Windows Phone Local Database

When to choose what?

Page 3: Play With Windows Phone Local Database

Persist data in my WP 8.1 (Silverlight) app

Local database (SQLCE) saves the dayStore relational dataSits in app’s local folderUse LINQ TO SQL for

CREATE

RETRIEVE

UPDATE

DELETE

Page 4: Play With Windows Phone Local Database

What about Windows Phone Apps under WinRT framework?

Page 5: Play With Windows Phone Local Database

Third party database support!

SQLite for Windows Phone 8.1World’s most popular database Used in other OS tooFast & ReliableSupport for multiple tables, triggers, views, indicesFollow ACID rules

Page 6: Play With Windows Phone Local Database

What you need to know when using database in WP 8.1 (Silverlight)

Page 7: Play With Windows Phone Local Database

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 entitiesEntity is a “plain old CLR object” (POCO) with attributes.

Page 8: Play With Windows Phone Local Database

Behind the scene!

BlogId BlogName

Value Value

Blogs Table

PostId PostName

Value Value

Posts Table

BlogPostDatacontext

Page 9: Play With Windows Phone Local Database

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

Page 10: Play With Windows Phone Local Database

How it really works!

DataContext and Local database relation

Data Context Local DatabaseLINQ TO SQL

RUNTIME

Page 11: Play With Windows Phone Local Database

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)

Page 12: Play With Windows Phone Local Database

Teach LINQ TO SQL what to do

PostId (Pk) PostContent

Value (NOT NULL)(AUTOINCREMENT)(INT)

Value

Post Table

Page 13: Play With Windows Phone Local Database

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

Page 14: Play With Windows Phone Local Database

Association dissection!

Foreign Key

Navigational Property(Blog Reference)

Post list reference

Page 15: Play With Windows Phone Local Database

Its time for CRUD

Page 16: Play With Windows Phone Local Database

CRUD with LINQ

SELECT/RETRIEVE

INSERT/CREATE

UPDATE

DELETE

After All_blogPostDataContext.SubmitChanges();

Page 17: Play With Windows Phone Local Database

DEMO

Page 18: Play With Windows Phone Local Database

What you need to know when using database in WP 8.1 (WinRT)