1 / 40

SQL CE & Windows Phone

The easy way. SQL CE & Windows Phone. Paul Scivetti paul@synergensoftware.com @ TheIdeaGuy BuzzTheCloud.com. January 17, 2012. SQL CE + Win Phone!. Table Designer. Stored Procs. MS Dev Tools. T-SQL. Entity Framework. L2S + “Code First”. Seriously?. #%*$!!. SQL CE . Better

lara
Download Presentation

SQL CE & Windows Phone

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The easy way SQL CE & Windows Phone Paul Scivetti paul@synergensoftware.com @TheIdeaGuy BuzzTheCloud.com • January 17, 2012

  2. SQL CE + Win Phone!

  3. Table Designer Stored Procs MS Dev Tools T-SQL Entity Framework

  4. L2S + “Code First”

  5. Seriously?

  6. #%*$!! SQL CE

  7. Better Way?

  8. Simple • Useful • Balanced

  9. SQL CE Basics • Tools • Using L2S • Performance

  10. Demo

  11. SQL CE Basics • Where is the Database? • Create / Modify Database • Create Tables

  12. Where is the Database? usingSystem.Data.Linq; public partialclass DBDataContext : DataContext { public DBDataContext() : base("Data Source=isostore:/PhoneDemoDB.sdf") { OnCreated(); } }

  13. Create Database DBDataContext db = new DBDataContext(); if (!db.DatabaseExists()) { db.CreateDatabase(); var updater = db.CreateDatabaseSchemaUpdater(); updater.DatabaseSchemaVersion = DB_CURRENT_VERSION; updater.Execute(); }

  14. Update Schema var updater = db.CreateDatabaseSchemaUpdater(); intdbVersion = updater.DatabaseSchemaVersion ; if (dbVersion < DB_CURRENT_VERSION) { if (dbVersion < 2) { updater.AddTable<Log>(); updater.AddColumn<Food>("Calories"); } updater.DatabaseSchemaVersion = DB_CURRENT_VERSION; updater.Execute(); }

  15. Code

  16. SQL CE Basics • Where is the Database? • Create / Modify Database • Create Tables

  17. #%*$!! SQL CE

  18. SQL CE Basics • Tools • Using L2S • Performance

  19. 1. Design Tables 4. Use L2S in App 2. Run SQLMetal 3. Tweak code

  20. SQLMetal • Windows SDK • Command line tool • Generates mapping classes • AlmostWinPhone Compatible

  21. .\SqlMetal.exe /server:.\sqlexpress/database:phonedemo/code:c:\metal\phonedemo.cs/context:DBDataContext/pluralize/namespace:PhoneApp2

  22. Code

  23. SQL CE Basics • Tools • Using L2S • Performance

  24. Query Syntax: DBDataContext db = new DBDataContext(); varqry = from f in db.Foods orderbyf.Description select f; foreach (Food item in qry) { // process each food item }

  25. Fluent Syntax: DBDataContext db = new DBDataContext(); varqry = db.Events.OrderByDescending(o => o.MeetingDate) .ThenBy(o => o.Topic); foreach (Event item in qry) { // process each event }

  26. CRUD: Insert DBDataContext db = new DBDataContext(); Food f = new Food(); f.Description = “Mushroom Pizza”; db.Foods.InsertOnSubmit(f); db.SubmitChanges();

  27. Code

  28. SQL CE Basics • Tools • Using L2S • Performance

  29. Async Access using System.Threading.Tasks; private async void LoadFoodAsync() { ObservableCollection<Food> res = new ObservableCollection<Food>(); await TaskEx.Run(() => { DBContext db = new DBContext(); varqry = from s in db.Food select s; res = new ObservableCollection<Food>(qry); }); this.FoodItems = res; }

  30. Performance Tuning usingSystem.Data.Linq; public partial class DBDataContext : DataContext { // default buffer size: 384K public DBDataContext() : base("Data Source=isostore: /PhoneDemoDB.sdf;max buffer size=1024") { OnCreated(); } }

  31. Resources Windows Phone Development create.msdn.com LINQ to SQL

  32. The easy way SQL CE & Windows Phone Paul Scivetti paul@synergensoftware.com @TheIdeaGuy BuzzTheCloud.com • January 17, 2012

  33. The easy way SQL CE & Windows Phone Paul Scivetti paul@synergensoftware.com @TheIdeaGuy BuzzTheCloud.com • January 17, 2012

More Related