3. ethos http://www.ethostechnologies.com/ One of the 1st ISVs for cloud computing in Europe and China. Cloud computing development partner with Microsoft in Greater China Region. Invited to speak about Azure at several Microsoft events.
4. about anytao| Ethos <ethos:Member id = “Wang Tao” msn = anytao@live.com weibo = http://weibo.com/anytao runat = “Senior System Architect” /> Jason | Ethos <ethos:Member id = “Li Jingnan” msn = zengnami@hotmail.com weibo= http://weibo.com/jn1981 runat = “SE” />
7. session outline LINQ to SQL LINQ to User Data overview architecture code-first development implementation details queries inserts, updates, deletes… database schema upgrades performance and best practices overview end-user consent supported account types implementation details querying contacts querying appointments performance and best practices
9. complex schema numerous relationships and constraints example: shopping list 7 tables 100s of records 5 foreign keys
10. Reference Data Huge amounts of static reference data Example: dictionary app 3 tables 1 table with 500k rows
11. web service cache Cloud Service fetch reference data from cloud cache it locally combine with user-specific data Windows Phone Service Cache User Data
12. user data filter contacts birthdays in the next month query all appointments find an available time for a meeting Filter
23. queries: examples // Create the database form data context, using a connection string DataContextdb = newWineDataContext("isostore:/wineDB.sdf"); // Find all wines currently at home, ordered by date acquired varq = from w indb.Wines wherew.Varietal.Name == “Shiraz” && w.IsAtHome == true orderbyw.DateAcquired select w;
24. Inserts/Updates/Deletes Your App Code It’s all about the DataContext Changes made against the DataContext first Changes persisted by calling SubmitChanges() SubmitChanges LINQ to SQL determines change set and submits to DB DataContext DB
25. inserts/updates/deletes update insert WinenewWine= newWine { WineID= “1768", Name = “Windows Phone Syrah", Description = “Bold and spicy" }; db.Wines.InsertOnSubmit(newWine); db.SubmitChanges(); Winewine= (fromw indb.Wines wherew.WineID== “1768" select w).First(); wine.Description= “Hints of plum and melon"; db.SubmitChanges();
26. inserts/updates/deletes delete varvineyardsToDelete= fromVineyards v in db.Vineyards wherev.Country== “Australia” select v; db.Vineyards.DeleteAllOnSubmit (vineyardsToDelete); db.SubmitChanges(); Foreign key constraint will cause exception here if Wines associated with the Vineyards are not deleted first
27. inserts/updates/deletes varvineyardsToDelete= fromVineyards v indb.Vineyards wherev.Country== “Australia" select v; foreach (Vineyards v invineyardsToDelete) { db.Wines.DeleteAllOnSubmit(v.Wines); } db.Vineyards.DeleteAllOnSubmit(vineyardsToDelete); db.SubmitChanges();
28. database schema upgrades DatabaseSchemaUpdater allows for simple upgrades on your existing DB It offers the ability to add Tables Columns Indices Associations/foreign keys All schema updates are transactional More complex schema upgrades require full DB migration
29. Database Schema Upgrades Create a new DatabaseSchemaUpdater MyDerivedDataContext context = newMyDerivedDataContext("foo.sdf");DatabaseSchemaUpdaterdbUpdater = context.CreateDatabaseSchemaUpdater(); Add a new table tied to the Product class dbUpdater.AddTable<Winemaker>(); Add a Region column to the Customer table dbUpdater.AddColumn<Vineyard>(“YearEstablished"); Execute upgrade dbUpdater.Execute();
30. performance and best practices keep change sets small Submit early and often to avoid data loss on app termination use background threads Non-trivial operations will impact app responsiveness if done on UI thread optimize read-only queries Set ObjectTrackingEnabled to minimize memory usage use secondary indices for properties which you query often
31. performance and best practices populate large reference data tables in advance Create a simple project to prepopulate data in emulator Pull out database file using Isolated Storage explorer when to use a database… expect some impact to startup time and memory usage from incorporating a DB stick to IsolatedStorageSettings or basic files for small data sets
33. new and updated APIs in “Mango” Chooser Tasks related to user data EmailAddressChooserTask PhoneNumberChooserTask AddressChooserTask Microsoft.Phone.UserData for direct access Contacts Appointments
37. contacts: hello, world! Contactscontacts = newContacts(); contacts.SearchCompleted+= newEventHandler<ContactsSearchEventArgs>((sender, e) => { ...= e.Results; }); // E.g. search for all contacts contacts.SearchAsync(string.Empty, FilterKind.None, null); state // E.g. search for all contacts with display name matching "ja" contacts.SearchAsync("ja", FilterKind.DisplayName, null); filter expression (not a regex) Filter kind: name, email , phone or pinned to start)
38. appointments: hello, world! Appointmentsappointments = newAppointments(); appointments.SearchCompleted+= newEventHandler<AppointmentsSearchEventArgs>((sender, e) => { ... = e.Results; }); // E.g. get next appointment (up to 1 week away) appointments.SearchAsync(DateTime.Now, DateTime.Now+ TimeSpan.FromDays(7), 1, null); start date and time end date and time Maximum items to return state
39. performance and best practices be responsible your privacy policy should cover how you use the user’s contact information keep out of the way users have widely varying contact list sizes your UI should handle delays gracefully don’t let data get stale data returned is a snapshot refresh state when reasonable
40. demo 35 / linq to sql / datacontext / CRUD / user data 04 user manager