using System.Collections.Generic;
using System.Windows;
using WpfApplication1.NorthwindTableAdapters;
using System.Collections;
using System.Linq;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            DataContext = new Northwind();
        }
    }

    public partial class Northwind
    {
        CustomersDataTable _AllCustomers;
        public CustomersDataTable AllCustomers
        {
            get
            {
                if (_AllCustomers == null && this.Customers.Count == 0)
                {
                    new CustomersTableAdapter().Fill(this.Customers);
                    _AllCustomers = this.Customers;
                }

                return _AllCustomers;
            }
        }

        public partial class CustomersRow
        {
            OrdersDataTable _CustomerOrders;
            public OrdersDataTable CustomerOrders
            {
                get
                {
                    if (_CustomerOrders == null)
                    {
                        if (((Northwind)this.Table.DataSet).Orders.Count == 0)
                        {
                            new OrdersTableAdapter().Fill(((Northwind)this.Table.DataSet).Orders);
                        }

                        _CustomerOrders = new OrdersDataTable();
                        GetOrdersRows().ToList().ForEach(_CustomerOrders.ImportRow);
                    }

                    return _CustomerOrders;
                }
            }
        }
    }
}
