1 / 8

Displaying and Editing Data by Using the Entity Framework and Data Binding

Displaying and Editing Data by Using the Entity Framework and Data Binding. Fehim Korhan YAMAN 2008514024. Entity Framework and Data Model. Entity Framework is a technology that is used for querying and manipulating databases. Entity data model is a logical model of a database.

kenaz
Download Presentation

Displaying and Editing Data by Using the Entity Framework and Data Binding

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. Displaying and Editing Data by Using the Entity Framework and Data Binding Fehim Korhan YAMAN 2008514024

  2. Entity Framework and Data Model • Entity Framework is a technology that is used for querying and manipulating databases. • Entity data model is a logical model of a database. • We use the entity framework to generate a logical data model.

  3. RetrievingInformationand Establishingthe DataBindings • using System.ComponentModel; • using System.Collections; • public partial class SupplierInfo : Window • { • private NorthwindEntities northwindContext = null; • private Supplier supplier = null; • private IList productsInfo = null; • ... • }

  4. RetrievingInformation and Establishing the DataBindings • private void Window_Loaded(object sender, RoutedEventArgs e) • { • this.northwindContext = new NorthwindEntities(); • suppliersList.DataContext = this.northwindContext.Suppliers; • } • private void suppliersList_SelectionChanged(object sender, • SelectionChangedEventArgs e) • { • this.supplier = suppliersList.SelectedItem as Supplier; • this.northwindContext.LoadProperty<Supplier>(this.supplier, s => s.Products); • this.productsInfo = ((IListSource)supplier.Products).GetList(); • productsList.DataContext = this.productsInfo; • }

  5. Using LINQ to Entities to Query Data • NorthwindEntities northwindContext = new NorthwindEntities(); • ObjectQuery<Product> products = northwindContext.Products; • var productNames = from p in products • select p.ProductName; • foreach (var name in productNames) • { • Console.WriteLine("Product name: {0}", name); • }

  6. Using Data Binding for Data editing • NorthwindEntities northwindContext = new NorthwindEntities(); • try • { • Product product = northwindContext.Products.Single(p => p.ProductID == 14); • product.ProductName = "Bean Curd"; • northwindContext.SaveChanges(); • } • catch (OptimisticConcurrencyException ex) • { • northwindContext.Refresh(RefreshMode.ClientWins, northwindContext.Products); • northwindContext.SaveChanges(); • }

  7. QUESTIONS?

  8. References • Microsoft Visual C#2010 Step by Step

More Related