Menu

Using Joins

huss
2006-08-22
2013-04-22
  • huss

    huss - 2006-08-22

    Hi There,
    Is there an example on how to perform joins.?
    Thanks

     
    • Richard Beauchamp

      Hi,

      Take a look at the DomainObjects unit tests, especially DomainObjects.Test.TestFixture.QueryTests and DomainObjects.Test.TestFixture.OuterJoinTests.

      Joins are automatically generated by DomainObjects when you specify a path in your Criteria.

      For example, see the following unit test:

          /// <summary>
          /// Tests Criteria.AddEqualTo() with an inner join in the reference path
          /// </summary>
          [Test]
          public void AddEqualToWithInnerJoin()
          {
            // Create a new instance of Criteria
            Criteria criteria = new Criteria();

            // Constrain the search to products where the product category name is 'Liquors'.
            // Note that, because the '_productCategory' argument represents an object referenced
            // by Product, DomainObjects will automatically generate SQL that contains
            // an inner join between the PRODUCT table and the referenced PRODUCT_CATEGORY table.
            criteria.AddEqualTo(Types.Product._productCategory.Field._name, "Liquors");

            // Query the database, i.e., find the list of objects of type Product
            // that match the given criteria.
            List<Product> results = QueryFacade.FindObjectSet<Product>(criteria);

            Assert.Greater(results.Count, 0, "Found some results.");
          }

      Hope this helps,

      Richard

       
    • huss

      huss - 2006-08-22

      Great!
      Thanks for the quick reply.

       
    • huss

      huss - 2006-08-22

      That was simple enough.
      I have also looked at the outer joins test.
      Thanks a lot.

       

Log in to post a comment.