public ClientSideQuerying()
        {
            InitializeComponent();

            // Define and bind a live view of expensive non-discontinued products ordered by price.
            _viewProducts =
                (from p in _scope.GetItems <Product>()
                 where !p.Discontinued && p.UnitPrice >= 30
                 orderby p.UnitPrice
                 select new
            {
                ProductID = p.ProductID,
                ProductName = p.ProductName,
                CategoryID = p.CategoryID,
                CategoryName = p.Category.CategoryName,
                SupplierID = p.SupplierID,
                Supplier = p.Supplier.CompanyName,
                UnitPrice = p.UnitPrice,
                QuantityPerUnit = p.QuantityPerUnit,
                UnitsInStock = p.UnitsInStock,
                UnitsOnOrder = p.UnitsOnOrder
            }).AsDynamic();      // AsDynamic() is required for data binding because an anonymous class is used (select new...)

            dataGrid1.ItemsSource = _viewProducts;

            // Define a view of seafood products. Filtering is performed on the server.
            _seafoodProductsView = _scope.GetItems <Product>().AsFiltered(p => p.CategoryID == 8);

            // Bind the label text to the number of products in the view
            textBlockCount.SetBinding(TextBlock.TextProperty, new Binding("Value")
            {
                Source = _viewProducts.LiveCount()
            });
        }
Example #2
0
        public CategoryProductsViewModel()
        {
            // These binding sources will be used by the CategoryProductsView
            // to display categories and products.
            Categories = new BindingSource(
                from c in _scope.GetItems <Category>()
                select new CategoryViewModel()
            {
                CategoryID   = c.CategoryID,
                CategoryName = c.CategoryName
            }, null);

            // Products are filtered by CategoryID on the server.
            // Filtering is performed automatically when the current Category changes.
            // Product suppliers are fetched along with the products.
            Products = new BindingSource(
                from p in _scope.GetItems <Product>().AsFilteredBound(p => p.CategoryID)
                .BindFilterKey(Categories, "Current.CategoryID").Include("Supplier")
                select new ProductViewModel()
            {
                ProductID       = p.ProductID,
                ProductName     = p.ProductName,
                CategoryID      = p.CategoryID,
                CategoryName    = p.Category.CategoryName,
                SupplierID      = p.SupplierID,
                SupplierName    = p.Supplier.CompanyName,
                UnitPrice       = p.UnitPrice,
                QuantityPerUnit = p.QuantityPerUnit,
                UnitsInStock    = p.UnitsInStock,
                UnitsOnOrder    = p.UnitsOnOrder
            }, null);
        }
        public DataSourcesInCode()
        {
            InitializeComponent();

            // Bind the category combo box to the category view
            // and show the products of the first category in the data grid.

            ClientView <Category> viewCategories = _scope.GetItems <Category>();

            comboBox1.DisplayMemberPath = "CategoryName";
            comboBox1.ItemsSource       = viewCategories;

            BindGrid(viewCategories.First().CategoryID);
        }
Example #4
0
        public MainWindow()
        {
            InitializeComponent();

            // Initialize the client cache and the client scope.
            _clientCache = new EntityClientCache(new NORTHWNDEntities());
            _scope       = new EntityClientScope(_clientCache);

            // Bind a combo box to the list of cities
            // using a live view of customers grouped by city.
            comboCity.ItemsSource =
                (from c in _scope.GetItems <Customer>()
                 group c by c.City into g
                 orderby g.Key
                 select new
            {
                City = g.Key,
                Customers = g
            }).AsDynamic();
        }