Name of Experiment: Country Database

Similar documents
Step4: Now, Drag and drop the Textbox, Button and Text block from the Toolbox.

Name of Experiment: Student Database

Hands-On Lab. Using Pivot and Panorama Controls

Week 8: Data Binding Exercise (Bookstore)

Note: This demo app created for this lab uses the Visual Studio 2015 RTM and Windows Tools SDK ver

Launchers and Choosers Hands-on Lab. Hands-On Lab. Launchers and Choosers. Lab version: Last updated: 12/8/2010. Page 1

FOREWORD WHAT WE CAN LEARN TARGET READER

Lecture # 6 Engr. Ali Javed 11th March, 2014

Migrating to Windows Phone

Creating your first Windows Phone application

SAMPLE CHAPTER IN ACTION. Timothy Binkley-Jones Adam Benoit Massimo Perga Michael Sync MANNING

S AMPLE CHAPTER IN ACTION. Timothy Binkley-Jones Massimo Perga Michael Sync MANNING

Week 7: NavigationView Control Exercise

Workspace Desktop Edition Developer's Guide. Customize Views and Regions

Hands-On Lab. Hello Windows Phone

Hands-On Lab. Sensors -.NET. Lab version: Last updated: 12/3/2010

Microsoft Corporation

Introduction to Data Templates and Value Converters in Silverlight

Media Programming on mobile devices (Windows Phone)

Portable Class Libraries ---

WebFront for Service Manager

Hands-On Lab. Windows Phone Navigation and Controls

RadPDFViewer For Silverlight and WPF

Lesson 9: Exercise: Tip Calculator

This tutorial is designed for software developers who want to learn how to develop quality applications with clean structure of code.

Authoring Guide Gridpro AB Rev: Published: March 2014

Programos gyvavimo ciklas

Weather forecast ( part 2 )

sharpcorner.com/uploadfile/37db1d/4958/default.aspx?articleid=cb0b291c-52ae-4b80-a95c- 438d76fa1145

Master Code on Innovation and Inclusion

CPSC Tutorial 5

Hands-On Lab. Using Bing Maps

windows-10-universal #windows- 10-universal

Authoring Guide v2.1 PATRIK SUNDQVIST

ComponentOne. Extended Library for UWP

SAMPLE CHAPTER. C# and XAML. Pete Brown MANNING

CPSC Tutorial 5 WPF Applications


S AMPLE CHAPTER IN ACTION. Timothy Binkley-Jones Massimo Perga Michael Sync MANNING

Hands-On Lab. Building Applications in Silverlight 4 Module 6: Printing the Schedule. Printing the Schedule

Week 6: First XAML Control Exercise

Accurate study guides, High passing rate! IT TEST BOOK QUESTION & ANSWER. Ittestbook provides update free of charge in one year!

Hands-On Lab. Building Applications in Silverlight 4 Module 7: Event Administrator Dashboard with Out of Browser, Toasts and Native Integration

Exam sell. Higher Quality Better Service! Certified IT practice exam authority.

RadGanttView For Silverlight and WPF

While the press might have you believe that becoming a phoneapp

Sparkline for WPF 1. ComponentOne. Sparkline for WPF

var xdoc = XDocument.Load(inStream);

Lab 7: Silverlight API

Chromatic Remote Control Product Guide Executive Way, Suite A Frederick, MD 21704

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C1: The Intro Project

CS3240 Human-Computer Interaction Lab Sheet Lab Session 4 Media, Ink, & Deep Zoom

Note: many examples in this section taken or adapted from Pro WPF 4.5 C#, Matthew MacDonald, apress, 2012, pp

Yes, this is still a listbox!

Windows Phone Recipes. A Problem-Solution Approach

ComponentOne. Xamarin Edition

The Model provides underlying data, sometimes involving file or web accesses.

ComponentOne. Imaging for UWP

WRITING THE MANAGEMENT SYSTEM APPLICATION

Exam Name: TS: Microsoft.NET Framework 3.5, Windows Presentation Foundation Application

CALCULATOR APPLICATION

Index. Windows 10 running, 199 suspended state, 199 terminate apps,

CS3240 Human-Computer Interaction

Integration with AppBar

Back to the future: sockets and relational data in your (Windows) pocket

Windows 10 Development: Table of Contents

ArcGIS Pro SDK for.net Advanced User Interfaces in Add-ins. Wolfgang Kaiser

1) ItemsSource: it point to collection which has all the objects that will be shown in the list

Universal Windows Platform Complete Solution

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

Developing Native Windows Phone 7 Applications for SharePoint

EXAM TS:Windows Apps Dev w/microsoft.net Framework 4((C# and VB) Buy Full Product.

Advance Windows Phone Development. Akber Alwani Window Phone 7 Development EP.NET Professionals User Group

This book was purchased by

Microsoft Exam TS: Windows Applications Development with Microsoft.NET Framework 4 Version: 58.5 [ Total Questions: 228 ]

CPSC Tutorial 6

C# Crash Course Dimitar Minchev

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Hello World 2. Installation or Setup 3

Mobile Computing Xamarin Data Binding MVVM Pattern

Windows Phone 8 Game Development

SAMPLE CHAPTER IN ACTION. Timothy Binkley-Jones Adam Benoit Massimo Perga Michael Sync MANNING

Exam Name: TS: Windows Applications Development with Microsoft.NET Framework 4

Visão Computacional: Reconhecimento da Mão Humana e Seus Movimentos. Licenciatura em Gestão de Sistemas e Computação. Visão Computacional:

Mobile Computing. Xamarin Data Binding MVVM Pattern. Data Binding. XAML binding example. Target Views. In simple apps. For complex or big apps

Windows 8 App Projects

Microsoft Windows Apps Dev w/microsoft.net Framework 4. Download Full Version :

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

About 1. Chapter 1: Getting started with xaml 2. Remarks 2. Versions 2. Examples 2. Installation or Setup 2. Hello World 2

Course 2D_SL: 2D-Computer Graphics with Silverlight Chapter C5: The Complete Code of PathAnimation. Copyright by V. Miszalok, last update:

WPF and MVVM Study Guides

User Interface Changes for SYSPRO

You can call the project anything you like I will be calling this one project slide show.

ArcGIS Pro SDK for.net: Advanced User Interfaces in Add-ins. Wolfgang Kaiser

This walkthrough assumes you have completed the Getting Started walkthrough and the first lift and shift walkthrough.

Getting Started. DevForce and Report Sharp-Shooter Silverlight Bundle. Software Prerequisites

New Insights into Process Deviations Using Multivariate. Control Charts

CertifyMe. CertifyMe

Microsoft Exam

ArcGIS Pro SDK for.net UI Design for Accessibility. Charles Macleod

Hands-On Lab. Using Push Notifications

Transcription:

Name of Experiment: Country Database Exp No: DB2 Background: Student should have basic knowledge of C#. Summary: Database Management is one of the key factors in any Mobile application development framework. We need to understand each aspect of database at all levels i.e. Physical level, Logical level and View level. In order to do so Windows Phone has MVVM architecture. Learning Objective: To learn the MVVM architecture in Database using this experiment. Target Platforms: This experiment is tested on Windows Phone Emulator and Nokia Lumia 800. Procedure: Step1. Repeat steps [1-4] as in Experiment no MC1. [Refer Hello World] Step2. Add Reference for Microsoft.Phone.Controls and add this line xmlns:controls="clrnamespace:microsoft.phone.controls;assembly=microsoft.phone.controls" to the Phone.ApplicationPage. Step3. Also, add reference for System.Data.Linq to the current experiment. Step4. Copy and paste the MainPage.xaml code from the source code section. Step5. Add New Folder and named it as Images by making right click on the Experiment Name. Step6. Copy required images from the Windows Phone SDK folder and placed inside the Images folder. Step7. Set the properties of each images as Build Action= Content and Copy to Output Directory= Copy always. Step8. Create two more folders and named it as Model and ViewModel. Step9. Add new class and named it as CountryDataContext.cs inside the Model folder.[refer Source Code Section] Step10.Open CountryDataContext.cs class and add using System, System.ComponentModel, System.Data.Linq and System.Data.Linq.Mapping Step11.CountryDataContext.cs class contains actual schema for the database. Here, we have two tables namely City and Country and their columns. DataContext interface is implemented in order to create the connectionstring to the database. We also, implement INotifyPropertyChanged event in order to track the changes and reflect back to the database. [Refer Source Code Section] Step12.Similarly, add new class CountryViewModel.cs inside the ViewModel folder.[refer Source Code Section]

Step13. Open CountryViewModel.cs class and using System.Linq, System.ComponentModel, CountryDatabase.Model, System.Collection.ObjectModel and System.Collection.Generic. Step14. Here, we initialise the CountryDB as DataContext object in order to link the Views to the Model. This class also contains various functionality like SaveChangesToDB(), LoadCollectionFromDatabase(), AddCity(), SearchCity() and DeleteCity() etc.[refer Source Code Section] Step15. Add new page named ItemSearch.xaml, design the UI as given in the snapshot then copy and paste the content inside ItemSearch.xaml.cs [Refer Source Code Section] Step16. Add one more new page named NewTaskPage.xaml, design the UI part as given in the snapshot then copy and paste the content inside NewTaskPage.xaml.cs class.[refer Source Code Section] Step17. Open the App.xaml.cs class, define viewmodel object before the constructor of the class. Now, inside the constructor define the DBConnectionString path and load the dropdown list as soon as the app is loaded. Step18. Now, at last open the MainPage.xaml.cs and copy and paste the content over there.[refer Source Code Section] Step19. Save all the changes made to the experiment. Step20.Press F5, in order to debug the experiment on the Windows Phone Emulator. Step21. In this manner, we are able to deployed the experiment on the Windows Phone Emulator. Source Code Comments MainPage.xaml <phone:phoneapplicationpage.resources> <DataTemplate x:key="todolistboxitemtemplate"> <Grid HorizontalAlignment="Stretch" Width="420"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="100" /> </Grid.ColumnDefinitions> <CheckBox IsChecked="False" Grid.Column="0" VerticalAlignment="Top" Background="DarkOliveGreen"/> <TextBlock Text="Binding CityName" FontSize="StaticResource PhoneFontSizeLarge" Grid.Column="1" Grid.ColumnSpan="2" VerticalAlignment="Top" Margin="-36, 12, 0, 0"/> <Button

Grid.Column="3" x:name="deletetaskbutton" BorderThickness="0" Margin="0, -18, 0, 0" Click="deleteTaskButton_Click"> <Image Source="/Images/appbar.delete.rest.png" Height="75" Width="75"/> </Button> </Grid> </DataTemplate> </phone:phoneapplicationpage.resources> <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:name="layoutroot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title--> <StackPanel x:name="titlepanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:name="experimenttitle" Text="Exp No:DB2" TextAlignment="Right" Style="StaticResource PhoneTextNormalStyle"/> <TextBlock x:name="applicationtitle" Text="Country Database" Style="StaticResource PhoneTextNormalStyle"/> <!--<TextBlock x:name="pagetitle" Text="page name" Margin="9,-7,0,0" Style="StaticResource PhoneTextTitle1Style"/>--> </StackPanel> <!--ContentPanel - place additional content here--> <Grid x:name="contentpanel" Grid.Row="1" Margin="12,0,12,0"> <controls:pivot Margin="0, -36, 0, 0"> <controls:pivotitem Header="all"> <ListBox x:name="alltodoitemslistbox" ItemsSource="Binding AllCities" Margin="12, 0, 12, 0" Width="440" ItemTemplate="StaticResource ToDoListBoxItemTemplate" /> </controls:pivotitem> <controls:pivotitem Header="india"> <ListBox x:name="hometodoitemslistbox" ItemsSource="Binding IndianCity" Margin="12, 0, 12, 0" Width="440" ItemTemplate="StaticResource ToDoListBoxItemTemplate" /> </controls:pivotitem> <controls:pivotitem Header="uk"> ExpNo: DB2 (ExperimentTitle) Country Database (ApplicationTitle) Pivot Page Display having different headers. all (Pivot Header) india (Pivot Header) uk (Pivot Header)

<ListBox x:name="worktodoitemslistbox" ItemsSource="Binding UKCity" Margin="12, 0, 12, 0" Width="440" ItemTemplate="StaticResource ToDoListBoxItemTemplate" /> </controls:pivotitem> <controls:pivotitem Header="usa"> <ListBox x:name="hobbiestodoitemslistbox" ItemsSource="Binding USACity" Margin="12, 0, 12, 0" Width="440" ItemTemplate="StaticResource ToDoListBoxItemTemplate" /> </controls:pivotitem> usa (Pivot Header) </controls:pivot> </Grid> </Grid> <!--Sample code showing usage of ApplicationBar--> <phone:phoneapplicationpage.applicationbar> <shell:applicationbar IsVisible="True" IsMenuEnabled="False"> <shell:applicationbariconbutton IconUri="/Images/appbar.new.rest.png" Text="new" x:name="newtaskappbarbutton" Click="newTaskAppBarButton_Click"/> <shell:applicationbariconbutton IconUri="/Images/appbar.feature.search.rest.png" Text="search" x:name="newsearchappbarbutton" Click="newSearchAppBarButton_Click"/> new (ApplicationBarButton) search(applicationbarbutton) </shell:applicationbar> </phone:phoneapplicationpage.applicationbar> </phone:phoneapplicationpage> NewTaskPage.xaml <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:name="layoutroot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title--> <StackPanel x:name="titlepanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:name="applicationtitle" Text="Country Database" Style="StaticResource PhoneTextNormalStyle"/> <TextBlock x:name="pagetitle" Text="city" Margin="9,-7,0,0" Style="StaticResource PhoneTextTitle1Style"/> </StackPanel> Country Database (ApplicationTitle) city (PageTitle) <!--ContentPanel - place additional content here-->

<Grid x:name="contentpanel" Grid.Row="1" Margin="12,0,12,0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="100"/> <RowDefinition Height="300"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <TextBlock Text="City Name:" Width="100" Margin="10,30,0,10" Grid.Column="0" Grid.Row="0"/> <TextBox x:name="newtasknametextbox" Height="100" Width="350" Grid.Column="1" Grid.Row="0" TextWrapping="Wrap"/> <TextBlock Text="Country" Width="100" Margin="10,30,0,10" Grid.Column="0" Grid.Row="1"/> <toolkit:listpicker x:name="categorieslistpicker" ItemsSource="Binding CountryList" DisplayMemberPath="Name" Grid.Row="1" Grid.Column="1"> CountryList picker </Grid> </Grid> </toolkit:listpicker> <!--Sample code showing usage of ApplicationBar--> <phone:phoneapplicationpage.applicationbar> <shell:applicationbar IsVisible="True" IsMenuEnabled="False"> <shell:applicationbariconbutton IconUri="/Images/appbar.check.rest.png" Text="ok" x:name="appbarokbutton" Click="appBarOkButton_Click"/> <shell:applicationbariconbutton IconUri="/Images/appbar.cancel.rest.png" Text="cancel" x:name="appbarcancelbutton" Click="appBarCancelButton_Click"/> ok (ApplicationBarButton) cancel(applicationbarbutton) </shell:applicationbar> </phone:phoneapplicationpage.applicationbar> </phone:phoneapplicationpage> ItemSearch.xaml <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:name="layoutroot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <!--TitlePanel contains the name of the application and page title--> <StackPanel x:name="titlepanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:name="applicationtitle" Text="Country Database" Country Database (ApplicationTitle)

Style="StaticResource PhoneTextNormalStyle"/> <TextBlock x:name="pagetitle" Text="search city" Margin="9,-7,0,0" Style="StaticResource PhoneTextTitle1Style"/> </StackPanel> search city (PageTitle) <!--ContentPanel - place additional content here--> <Grid x:name="contentpanel" Grid.Row="1" Margin="12,0,12,0"> <StackPanel Orientation="Vertical"> <TextBlock Text="Search" Style="StaticResource PhoneTextGroupHeaderStyle"/> <TextBox x:name="itemtosearch" Height="100" TextWrapping="Wrap" /> <Button x:name="searchbutton" Content="Go!" Click="SearchButton_Click" Height="75" Width="120" BorderBrush="Green" BorderThickness="5" Foreground="Wheat"/> <ListBox x:name="responselist" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="Binding Result" Width="350" Height="100"/> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </StackPanel> </Grid> </Grid> MainPage.xaml.cs using System; using System.Windows; using System.Windows.Controls; using Microsoft.Phone.Controls; using CountryDatabase.Model; namespace CountryDatabase public partial class MainPage : PhoneApplicationPage // Constructor public MainPage() InitializeComponent(); this.datacontext = App.ViewModel; private void newtaskappbarbutton_click(object sender, EventArgs e) NavigationService.Navigate(new Uri("/NewTaskPage.xaml", UriKind.Relative)); Adding namespaces NavigateTo NewTaskPage.xaml Page private void deletetaskbutton_click(object sender, RoutedEventArgs e)

the button. // Cast the parameter as a button. var button = sender as Button; if (button!= null) // Get a handle for the to-do item bound to City deletecity = button.datacontext as City; App.ViewModel.DeleteCity(deleteCity); // Put the focus back to the main page. this.focus(); protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e) // Save changes to the database. App.ViewModel.SaveChangesTODB(); private void newsearchappbarbutton_click(object sender, EventArgs e) NavigationService.Navigate(new Uri("/ItemSearch.xaml", UriKind.Relative)); NavigateTo ItemSearch.xaml Page NewTaskPage.xaml.cs using System; using Microsoft.Phone.Controls; using CountryDatabase.Model; Add namespaces namespace CountryDatabase public partial class NewTaskPage : PhoneApplicationPage public NewTaskPage() InitializeComponent(); this.datacontext = App.ViewModel; private void appbarokbutton_click(object sender, EventArgs e) // Confirm there is some text in the text box. if (newtasknametextbox.text.length > 0) // Create a new to-do item. City newtodoitem = new City CityName = newtasknametextbox.text, country = (Country)categoriesListPicker.SelectedItem ;

// Add the item to the ViewModel. App.ViewModel.AddCity(newToDoItem); // Return to the main page. if (NavigationService.CanGoBack) NavigationService.GoBack(); private void appbarcancelbutton_click(object sender, EventArgs e) // Return to the main page. if (NavigationService.CanGoBack) NavigationService.GoBack(); ItemSearch.xaml.cs using System; using Microsoft.Phone.Controls; using CountryDatabase.Model; namespace CountryDatabase public partial class NewTaskPage : PhoneApplicationPage public NewTaskPage() InitializeComponent(); this.datacontext = App.ViewModel; private void appbarokbutton_click(object sender, EventArgs e) // Confirm there is some text in the text box. if (newtasknametextbox.text.length > 0) // Create a new to-do item. City newtodoitem = new City CityName = newtasknametextbox.text, country = (Country)categoriesListPicker.SelectedItem ; Add namespaces Add new item for database // Add the item to the ViewModel. App.ViewModel.AddCity(newToDoItem); // Return to the main page. if (NavigationService.CanGoBack) NavigationService.GoBack();

private void appbarcancelbutton_click(object sender, EventArgs e) // Return to the main page. if (NavigationService.CanGoBack) NavigationService.GoBack(); ViewModel/CountryViewModel.cs using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.ComponentModel; using CountryDatabase.Model; ViewModel Class Add namespaces namespace CountryDatabase.ViewModel public class CountryViewModel : INotifyPropertyChanged private CountryDataContext CountryDB; public CountryViewModel(string todbconnectionstring) CountryDB = new CountryDataContext(toDBConnectionString); public void SaveChangesTODB() CountryDB.SubmitChanges(); #region INotifyPropertyChanges Members public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string propertyname) if (PropertyChanged!= null) PropertyChanged(this,new PropertyChangedEventArgs(propertyName)); #endregion private ObservableCollection<City> _allcities; public ObservableCollection<City> AllCities get return _allcities; set _allcities = value; NotifyPropertyChanged("All Cities"); private ObservableCollection<City> _indiancity; public ObservableCollection<City> IndianCity get return _indiancity; set _indiancity = value; NotifyPropertyChanged("Indian City"); private ObservableCollection<City> _ukcity; public ObservableCollection<City> UKCity get return _ukcity; set _ukcity = value; NotifyPropertyChanged("UK City"); Implement INotifyPropertyChanged interface Initialise connectionstring object

private ObservableCollection<City> _usacity; public ObservableCollection<City> USACity get return _usacity; set _usacity = value; NotifyPropertyChanged("USA City"); private List<Country> _countrylist; public List<Country> CountryList get return _countrylist; set _countrylist = value; NotifyPropertyChanged("Country List"); public void LoadCollectionFromDatabase() var citiesindb = from City c in CountryDB.Cities select c; AllCities = new ObservableCollection<City>(citiesInDB); var countriesindb = from Country ct in CountryDB.Countries select ct; foreach(country country in countriesindb) switch(country.name) case "India": IndianCity = new ObservableCollection<City>(country.city); case "UK": UKCity = new ObservableCollection<City>(country.city); case "USA": USACity = new ObservableCollection<City>(country.city); default: CountryList = CountryDB.Countries.ToList(); public void AddCity(City newcity) CountryDB.Cities.InsertOnSubmit(newCity); CountryDB.SubmitChanges(); AllCities.Add(newCity); switch (newcity.country.name) case "India": IndianCity.Add(newCity); case "UK": UKCity.Add(newCity); case "USA": USACity.Add(newCity); default: Adding new city to the database public bool SearchCity(string qcity)

var query = from item in CountryDB.Cities where item.cityname.contains(qcity) select item.cityname; if (query.firstordefault()!= null) return true; return false; public void DeleteCity(City delcity) AllCities.Remove(delCity); CountryDB.Cities.DeleteOnSubmit(delCity); switch (delcity.country.name) case "India": IndianCity.Remove(delCity); case "UK": UKCity.Remove(delCity); case "USA": USACity.Remove(delCity); default: CountryDB.SubmitChanges(); Model/CountryDataContext.cs using System; using System.Data.Linq.Mapping; using System.Data.Linq; using System.ComponentModel; namespace CountryDatabase.Model public class CountryDataContext : DataContext public CountryDataContext(string connectionstring) : base(connectionstring) public Table<City> Cities; public Table<Country> Countries; [Table] public class Country: INotifyPropertyChanged private string name; [Column] public string Name get return name; set if (name!= value) name = value; NotifyPropertyChanged("Name"); Deletion of the city from the database. Model Class Add namespace Implement DataContext interface Two tables namely, City and Country. Implement INotifyPropertyChanged interface private int id; [Column(IsPrimaryKey = true, CanBeNull = false, IsDbGenerated = true, DbType = "INT NOT NULL IDENTITY", AutoSync = AutoSync.OnInsert)]

public int ID get return id; set if (id!= value) id = value; NotifyPropertyChanged("ID"); private EntitySet<City> _city; [Association(Storage = "_city", OtherKey = "_countryid", ThisKey = "ID")] public EntitySet<City> city get return this._city; set this._city.assign(value); public Country() _city = new EntitySet<City>(new Action<City>(this.attach_city), new Action<City>(this.dettach_city)); private void attach_city(city cities) NotifyPropertyChanged("City"); cities.country = this; private void dettach_city(city cities) NotifyPropertyChanged("City"); cities.country = null; #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string propertyname) if (PropertyChanged!= null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); #endregion #region INotifyPropertyChanging Members public event PropertyChangingEventHandler PropertyChanging; private void NotifyPropertyChaning(string propertyname) if (PropertyChanging!= null) PropertyChanging(this, new PropertyChangingEventArgs(propertyName));

#endregion [Table] public class City: INotifyPropertyChanged,INotifyPropertyChanging Table City private int _cityid; [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)] public int CityID get return _cityid; set if (_cityid!= value) NotifyPropertyChanging("CityID"); _cityid = value; NotifyPropertyChanged("CityID"); private string _cityname; [Column] public string CityName get return _cityname; set if (_cityname!= value) _cityname = value; NotifyPropertyChanged("CityName"); [Column] internal int _countryid; private EntityRef<Country> _country; [Association(Storage = "_country", ThisKey = "_countryid", OtherKey = "ID", IsForeignKey = true)] public Country country get return _country.entity; set NotifyPropertyChanged("Country"); _country.entity = value; if (value!= null) _countryid = value.id; #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string

propertyname) if (PropertyChanged!= null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); #endregion #region INotifyPropertyChanging Members public event PropertyChangingEventHandler PropertyChanging; private void NotifyPropertyChanging(string propertyname) if (PropertyChanging!= null) PropertyChanging(this, new PropertyChangingEventArgs(propertyName)); #endregion

Screenshots: Fig. No.1 Home Page Fig. No.2 Add City Name Fig. No.3 Shows the Country Dropdown List Fig. No.4 Cities Added to corresponding country

Fig. No.5 Adding new City under UK Fig. No.6 Liverpool is added with corresponding country Fig. No.7 Adding new city under USA Fig. No.8 New York is added with corresponding country

Fig. No.9 All cities are displaying Fig. No.10 Search City Fig. No.11 Type name of city to be search Fig. No.12 Message box showing the response

Fig. no 13 Message box showing the response of the query Observations: It is observed by developer, that MVVM architecture is very flexible to use in Windows Phone during database management. It enhances the response for querying to the database in many folds.