WPH304
announcement
LINQ to SQL LINQ to User Data
LINQ Objects XML SQL User Data OData
Windows Phone Cloud service
Filter
demo
Database Support
Application Settings file App Creates/manages files and settings Application files App Data Folder Package Manager App Root Folder WP7 Isolated Storage APIs Install Database file Database file (r/o) Creates root folder sandboxed to App
Architecture.Call System.Linq.Queryable.Select(.Call System.Linq.Queryable.Where(.Constant(Table(Wines)), '(.Lambda #Lambda1)), '(.Lambda #Lambda2)).Lambda #Lambda1(db.Wines $w) { $w.Country == “USA" }.Lambda #Lambda2(w.Country $w) { $w.Name } var query = from w in db.Wines where w.Country == “USA" select w.Name; select Name from Wines where Country = “USA” Custom data context App objects Identity management Change tracking Update processing Object materialization Core ADO.NET (System.Data) SQLCE ADO.NET Provider (System.Data.SqlServerCe)
Design time Run time Database upgrade Varietals Wines Vineyards WineMakers
Database Creation: Example
Queries: Examples // Create the database form data context, using a connection string DataContext db = new WineDataContext("isostore:/wineDB.sdf"); // Find all wines currently at home, ordered by date acquired var q = from w in db.Wines where w.Varietal.Name == “Shiraz” && w.IsAtHome == true orderby w.DateAcquired select w;
NameLittle Penguin VarietalPinot Noir AtHome False NameLittle Penguin VarietalPinot Noir AtHome True NameLittle Penguin VarietalPinot Noir AtHome False Your app code NameYellow Tail VarietalPinot Noir AtHome True
Inserts/Updates/Deletes Wine newWine = new Wine { WineID = “1768", Name = “Windows Phone Syrah", Description = “Bold and spicy" }; db.Wines.InsertOnSubmit(newWine); db.SubmitChanges(); Wine wine = (from w in db.Wines where w.WineID == “1768" select w).First(); wine.Description = “Hints of plum and melon"; db.SubmitChanges(); Insert Update
Inserts/Updates/Deletes Delete var vineyardsToDelete = from Vineyards v in db.Vineyards where v.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
Inserts/Updates/Deletes var vineyardsToDelete = from Vineyards v in db.Vineyards where v.Country == “Australia" select v; foreach (Vineyards v in vineyardsToDelete) { db.Wines.DeleteAllOnSubmit(v.Wines); } db.Vineyards.DeleteAllOnSubmit(vineyardsToDelete); db.SubmitChanges();
Database Schema Upgrades WineDataContext wineDC = new WineDataContext(App.WineDBConnectionString); DatabaseSchemaUpdater dsu = wineDC.CreateDatabaseSchemaUpdater(); if (dsu.DatabaseSchemaVersion == 1) { dsu.AddColumn ("BottleType"); dsu.DatabaseSchemaVersion = 2; dsu.Execute(); }
demo
User Data
AddressChooserTask private AddressChooserTask addressChooserTask; // Constructor public MainPage() { this.addressChooserTask = new AddressChooserTask(); this.addressChooserTask.Completed += new EventHandler ( addressChooserTask_Completed); } private void addressChooserTask_Completed(object sender, AddressResult e) { if (null == e.Error && TaskResult.OK == e.TaskResult) {... = e.DisplayName;... = e.Address; }
Contact name and picture Other contact dataAppointments/events Windows Live SocialYES Windows Live Rolodex (user created and SIM import) YES n/a Exchange accounts (corporate plus Google, etc.) YES Operator Address BooksYES n/a FacebookYESNO Other networks in the People Hub (e.g., Twitter) NO
Contacts: Hello, World! Contacts contacts = new Contacts(); contacts.SearchCompleted += new EventHandler ((sender, e) => {... = e.Results; }); // E.g. search for all contacts contacts.SearchAsync(string.Empty, FilterKind.None, null); filter expression (not a regex) Filter kind: name, , phone or pinned to start) state // E.g. search for all contacts with display name matching "ja" contacts.SearchAsync("ja", FilterKind.DisplayName, null);
Appointments: Hello, World! Appointments appointments = new Appointments(); appointments.SearchCompleted += new EventHandler ((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 Maximum items to return state end date and time
demo
THANK YOU!
QUESTIONS? How do you enter? How am I selected? During each Windows Phone session the moderator will post a question; the first person to correctly answer the question and is called on by the moderator will potentially win * Restrictions apply please see contest rules for eligibility and restrictions. Contest rules are displayed in the Technical Learning Center at the WPH info counter
Visit the Windows Phone Technical Learning Center for demos and more… Business IT resources blogs.technet.com/b/ windows_phone_4_it_pros Business IT resources blogs.technet.com/b/ windows_phone_4_it_pros Developer resources create.msdn.com Developer resources create.msdn.com Experience Windows Phone 7 on-line and get a backstage pass Experience Windows Phone 7 on-line and get a backstage pass
Q&A
Scan the Tag to evaluate this session now on myTechEd Mobile
Resources Sessions On-Demand & CommunityMicrosoft Certification & Training Resources Resources for IT ProfessionalsResources for Developers Connect. Share. Discuss.