Your SlideShare is downloading. ×
0
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
WPF and Databases
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

WPF and Databases

1,902

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,902
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
45
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. WPF and Databases Linq-to-Entities, Data Persisters, Master Datail <ul><li>Doncho Minkov </li></ul><ul><li>Telerik School Academy </li></ul><ul><li>http://schoolacademy.telerik.com </li></ul><ul><li>Technical Trainer </li></ul><ul><li>http://www.minkov.it </li></ul>
  • 2. Table of Contents <ul><li>Data Access Layer </li></ul><ul><ul><li>Linq-to-Entities </li></ul></ul><ul><ul><li>Linq-to-XML </li></ul></ul><ul><li>Accessing the Data Layer </li></ul><ul><ul><li>DataContext </li></ul></ul><ul><li>Master Detail </li></ul><ul><li>Data Persister </li></ul><ul><li>Paging </li></ul><ul><li>WPF and Databases </li></ul>
  • 3. Data Access Layer
  • 4. Data Access Layer <ul><li>The Data Access Layer is a essential </li></ul><ul><ul><li>Used for access to the database </li></ul></ul><ul><li>Class Library with single EntityModel class </li></ul><ul><li>This way we can use the same DAL with many applications </li></ul>
  • 5. Data Access Layer Live Demo
  • 6. Accessing the Data Layer
  • 7. The DataContext <ul><li>When adding a reference to the DAL project </li></ul><ul><ul><li>We can instantiate an entity model in the XAML </li></ul></ul><ul><ul><li>And set it for DataContext </li></ul></ul><ul><li><Window </li></ul><ul><li>… </li></ul><ul><li>xmlns:datalayer=&quot; </li></ul><ul><li>clr-namespace:NorthwindDataLayer;assembly= </li></ul><ul><li>NorthwindDataLayer&quot;> </li></ul><ul><li><Window.DataContext> </li></ul><ul><li><datalayer:NorthwindEntities /> </li></ul><ul><li></Window.DataContext> </li></ul>
  • 8. Accessing DAL <ul><li>After instantiating the EntityModel we can simply bind some of the entities to a ItemCollection </li></ul><ul><ul><li>ListBox , ListView , TreeView , etc. </li></ul></ul><ul><li>In MVVM it is not possible to access the DAL directly </li></ul><ul><ul><li>Done through the ViewModel </li></ul></ul><ul><ul><li>In MVVM we need a DataPersister object </li></ul></ul><ul><li><TreeView x:Name=&quot;TreeViewCategories&quot; </li></ul><ul><li>ItemsSource=&quot;{Binding Categories}&quot;> </li></ul>
  • 9. Accessing the Data Layer Live Demo
  • 10. Master Detail
  • 11. Master Detail <ul><li>What is Master Detail? </li></ul><ul><ul><li>When selecting a Category </li></ul></ul><ul><ul><ul><li>Show category info </li></ul></ul></ul><ul><ul><ul><li>Show products in this category </li></ul></ul></ul><ListView Name=&quot;ListViewFamilies&quot; ItemsSource=&quot;{Binding}&quot; DisplayMemberPath=&quot;FamilyName&quot;/> <ListView DisplayMemberPath=&quot;Name&quot; ItemsSource=&quot;{Binding ElementName=ListViewFamilies, Path=SelectedItem}&quot;/>
  • 12. Master Datail in MVVM <ul><li>Consider we have the property Categories in the ViewModel </li></ul><ul><ul><li>Somehow it gets data from the Model </li></ul></ul><ul><ul><li>Since Categories is a IEnumerable we can get its ICollectionView </li></ul></ul><ul><ul><li>Now we got the CurrentItem </li></ul></ul><ul><ul><li>Can make property Products that returns the products of the CurrentItem </li></ul></ul>
  • 13. Master Detail Live Demo
  • 14. Data Persister The way to collect information
  • 15. What is a Data Persister? <ul><li>The Data Persister is the object that gives data to the Model </li></ul><ul><ul><li>Sometimes it is merged with the Model </li></ul></ul><ul><ul><li>It could be an EntityDataModel </li></ul></ul><ul><ul><li>It could be a Linq-to-XML object </li></ul></ul><ul><ul><li>It could just an object we created </li></ul></ul><ul><li>How the Data Persister helps? </li></ul><ul><ul><li>Easier for mocking (unit testing) </li></ul></ul><ul><ul><li>Better reusability </li></ul></ul>
  • 16. The DataPersister <ul><li>The DataPersister is the class that makes the connection with the Data (RDB, XML or object) </li></ul><ul><ul><li>Responsible for the CRUD </li></ul></ul><ul><ul><li>May have validation </li></ul></ul><ul><li>With this object the Model is pretty clean </li></ul><ul><ul><li>Almost no programming logic </li></ul></ul><ul><ul><li>Loose coupling </li></ul></ul>
  • 17. Data Persister Live Demo
  • 18. Paging What is paging and why we need it?
  • 19. What is Paging? <ul><li>A memory-management scheme </li></ul><ul><ul><li>A computer can store and retrieve data from secondary storage for use in main memory </li></ul></ul><ul><li>With paging the application retrieves data from secondary storage in same-size blocks called pages </li></ul><ul><li>Why use paging? </li></ul><ul><ul><li>Imagine a Database with over a million records </li></ul></ul><ul><ul><li>Store them in the dynamic memory at once? </li></ul></ul><ul><ul><ul><li>Or take them by pieces with 100 records? </li></ul></ul></ul>
  • 20. Paging <ul><li>TODO </li></ul>
  • 21. Paging Live Demo
  • 22. WPF and Databases With MVVM
  • 23. WPF and Databases <ul><li>Consider the usual case </li></ul><ul><ul><li>You have categories with products in a Database </li></ul></ul><ul><ul><li>CRUD operations should be implemented </li></ul></ul><ul><li>You have the following: </li></ul><ul><li>When selecting the DataContext of the Grid </li></ul><ul><ul><li>You get a Person object </li></ul></ul><Grid DataContext=&quot;{Binding Person}&quot;> <TextBox Text=&quot;{Binding Name}&quot;/> <TextBox Text=&quot;{Binding Age}&quot;/> </Grid>
  • 24. Categories Editor Live Demo
  • 25. WPF and Databases
  • 26. Exercises <ul><li>Create a database holding continents, countries and town. Countries have name, language, population and continent. Towns have name, population and country. Implement a WPF application that shows the continents in a ComboBox , countries in a ListView and the towns in a ListView and allows master-detail navigation. Use Entity Framework. Use paging and sorting for the long lists. </li></ul><ul><li>Implement add / edit / delete for the continents, countries, towns and languages. Handle the possible errors accordingly. Implement validation logic. </li></ul>
  • 27. Exercises (2) <ul><li>Add a flag for each country which should be a PNG image, stored in the database, displayed along with the country data. Implement &quot;change flag&quot; functionality by uploading a PNG image. </li></ul>

×