private void Window1_Loaded(object sender, RoutedEventArgs e) { IQueryable <Order> query = from o in db.Orders.Include("OrderDetails") //where o.OrderDate >= System.Convert.ToDateTime("1/1/2009") orderby o.OrderDate descending, o.Customer.LastName select o; this.OrderData = new OrdersCollection(query, db); IQueryable <Customer> customerList = from c in db.Customers where c.Orders.Count > 0 orderby c.LastName, c.FirstName select c; IQueryable <Product> productList = from p in db.Products orderby p.Name select p; this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource"); this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource"); this.MasterViewSource.Source = this.OrderData; CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("CustomerLookup"); customerSource.Source = customerList.ToList(); // A simple list is OK here since we are not editing Customers CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ProductLookup"); productSource.Source = productList.ToList(); // A simple list is OK here since we are not editing Products this.MasterView = (ListCollectionView)this.MasterViewSource.View; MasterView.CurrentChanged += new EventHandler(MasterView_CurrentChanged); this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View; }
private void LookupComboboxBindingWindow_Loaded(object sender, RoutedEventArgs e) { IQueryable <Order> query = from o in db.Orders //where o.OrderDate >= System.Convert.ToDateTime("1/1/2009") orderby o.OrderDate descending, o.Customer.LastName select o; this.OrderData = new OrdersCollection(query, db); // Make sure the lookup list is pulled from the same ObjectContext // (OMSEntities) that the order query uses above. // Also have to make sure you return a list of Customer entites and not a // projection of just a few fields otherwise the binding won't work). IQueryable <Customer> customerList = from c in db.Customers where c.Orders.Count > 0 orderby c.LastName, c.FirstName select c; CollectionViewSource orderSource = (CollectionViewSource)this.FindResource("OrdersSource"); orderSource.Source = this.OrderData; CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("CustomerLookup"); customerSource.Source = customerList; //.ToArray(); //.ToList(); // A simple list is OK here since we are not editing Customers this.View = (ListCollectionView)orderSource.View; }
private void MasterDetailBindingWindow_Loaded(object sender, RoutedEventArgs e) { IQueryable <Order> query = from o in db.Orders.Include("OrderDetails") //where o.OrderDate >= System.Convert.ToDateTime("1/1/2009") orderby o.OrderDate descending, o.Customer.LastName select o; this.OrderData = new OrdersCollection(query, db); // Make sure the lookup lists are pulled from the same ObjectContext // (OMSEntities) that the order query uses above. // Also have to make sure you return a list of whole entites and not a // projection of just a few fields otherwise the binding won// t work. IQueryable <Customer> customerList = from c in db.Customers where c.Orders.Count > 0 orderby c.LastName, c.FirstName select c; IQueryable <Product> productList = from p in db.Products orderby p.Name select p; this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource"); this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource"); this.MasterViewSource.Source = this.OrderData; CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("CustomerLookup"); customerSource.Source = customerList.ToList(); // A simple list is OK here since we are not editing Customers CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ProductLookup"); productSource.Source = productList.ToList(); // A simple list is OK here since we are not editing Products this.MasterView = (ListCollectionView)this.MasterViewSource.View; MasterView.CurrentChanged += new EventHandler(MasterView_CurrentChanged); this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View; }