Implementing the Query Scenario

In this task, you will use the conceptual model to Query the Database and bind the result to your controls.
 
  To bind the Controls to the Data
  1. In the Solution Explorer, select AspectizeDALDemo Form, right click and Select View Code.

  2. Paste the following Code (don't forget to fill your Connection String):

        IDataManager dm;

        public AspectizeDALDemo()
        {
            InitializeComponent();

            Aspectize.Core.DAL.SchemaManagerContext.Initialize();

            dm = EntityManager.FromConnectionString(@"", SGBD.SQLServer2005);
        }

  1. Double-click the Form: this opens the code page for the form and creates the AspectizeDALDemo_Load event handler method.

  2. Paste the following Code:

            dm.LoadFullDomain<AdventureWorks.Production.NamespaceProvider>();

            IEntityManager em = dm as IEntityManager;

            List<ProductCategory> productCategories = em.GetAllInstances<ProductCategory>();

            lstProductCategory.DataSource = productCategories;

            lstProductCategory.DisplayMember = "Name";

  1. Double-click the Combobox lstProductCategory: this creates the lstProductCategory_SelectedIndexChanged event handler method.

  2. Paste the following Code:

            ProductCategory selectedCategory = (ProductCategory) lstProductCategory.SelectedItem;

            List<AdventureWorks.Production.ProductSubcategory> subCategories = selectedCategory.GetAssociatedInstances<ProductSubcategory, ProductSubcategoryProductCategory>();

            lstProductSubcategory.DataSource = subCategories;

            lstProductSubcategory.DisplayMember = "Name";


  1. Double-click the Combobox lstProductSubcategory: this creates the lstProductSubcategory_SelectedIndexChanged event handler method.

  2. Paste the following Code:

            ProductSubcategory selectedProductSubcategory = (ProductSubcategory) lstProductSubcategory.SelectedItem;

            List<AdventureWorks.Production.Product> products = selectedProductSubcategory.GetAssociatedInstances<Product, ProductProductSubcategory>();

            dgvProduct.DataSource = products;