コード例 #1
0
        private void ExecuteButton_Click(object sender, EventArgs e)
        {
            using (var context = new NorthWindAccessContext())
            {
                var customerData = (from customer in context.Customers
                                    join country in context.Countries on customer.CountryIdentifier equals country.CountryIdentifier
                                    select new CustomerEntity
                {
                    CustomerIdentifier = customer.CustomerIdentifier,
                    CustomerName = customer.CompanyName,
                    CountryIdentifier = customer.CountryIdentifier,
                    Country = country.Name
                }).ToList();


                var countryId = ((Countries)CountryComboBox.SelectedItem).CountryIdentifier;
                if (countryId > -1)
                {
                    customerData = customerData.Where(customer => customer.CountryIdentifier == countryId).ToList();
                }

                if (!string.IsNullOrWhiteSpace(CustomerNameStartsWithTextBox.Text))
                {
                    customerData = customerData.Where(customer => EF.Functions.Like(customer.CustomerName, "La%")).ToList();
                }


                _customersView = new BindingListView <CustomerEntity>(customerData);
                _customersBindingSource.DataSource = _customersView;
                dataGridView1.DataSource           = _customersBindingSource;
            }
        }
コード例 #2
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            dataGridView1.AutoGenerateColumns = false;

            using (var context = new NorthWindAccessContext())
            {
                var countries = context.Countries.ToList();
                countries.Insert(0, new Countries()
                {
                    Name = "Select", CountryIdentifier = -1
                });
                CountryComboBox.DataSource = countries;

                var customerData = (from customer in context.Customers
                                    join country in context.Countries on customer.CountryIdentifier equals country.CountryIdentifier
                                    select new CustomerEntity
                {
                    CustomerIdentifier = customer.CustomerIdentifier,
                    CustomerName = customer.CompanyName,
                    CountryIdentifier = customer.CountryIdentifier,
                    Country = country.Name
                }).ToList();



                _customersView = new BindingListView <CustomerEntity>(customerData);
                _customersBindingSource.DataSource = _customersView;
                dataGridView1.DataSource           = _customersBindingSource;
            }
        }