Play With Windows Phone Local Database
-
Upload
fiyaz-hasan -
Category
Technology
-
view
375 -
download
0
Transcript of Play With Windows Phone Local Database
![Page 1: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/1.jpg)
When database matters!
Fiyaz Bin HasanFormer MSP (AUST) , NerdCats
![Page 2: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/2.jpg)
When to choose what?
![Page 3: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/3.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/4.jpg)
What about Windows Phone Apps under WinRT framework?
![Page 5: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/5.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/6.jpg)
What you need to know when using database in WP 8.1 (Silverlight)
![Page 7: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/7.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/8.jpg)
Behind the scene!
BlogId BlogName
Value Value
Blogs Table
PostId PostName
Value Value
Posts Table
BlogPostDatacontext
![Page 9: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/9.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/10.jpg)
How it really works!
DataContext and Local database relation
Data Context Local DatabaseLINQ TO SQL
RUNTIME
![Page 11: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/11.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/12.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/13.jpg)
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](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/14.jpg)
Association dissection!
Foreign Key
Navigational Property(Blog Reference)
Post list reference
![Page 15: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/15.jpg)
Its time for CRUD
![Page 16: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/16.jpg)
CRUD with LINQ
SELECT/RETRIEVE
INSERT/CREATE
UPDATE
DELETE
After All_blogPostDataContext.SubmitChanges();
![Page 17: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/17.jpg)
DEMO
![Page 18: Play With Windows Phone Local Database](https://reader030.fdocuments.us/reader030/viewer/2022021509/58eed8e11a28ab6c278b45e1/html5/thumbnails/18.jpg)
What you need to know when using database in WP 8.1 (WinRT)