Login Skip Navigation LinksWilsonORMapper > Examples > Relations Search
Demo Version Demo Version
Download and try for yourself a fully working demo version, including sample apps and documentation.  The only limitation is that the demo version only works inside the debugger.

PayPal Subscribe
Get It All for $50 USD:
WebPortal, ORMapper,
Source Code, All Updates
PayPal

Wilson ORMapper Examples Wilson ORMapper Examples

Relationship Examples

using System;
using Wilson.ORMapper;

namespace Wilson.Examples
{
  publicsealedclass Global
  {
    publicstatic ObjectSpace Manager; // See Initialization Example

    privatestaticvoid RunExamples() {
      // This example uses code to demostrate all types of Relationships
      // Note that they are automatically displayed in Hierarchical Grids
      // Also note that inthiscase all Relationships were Lazy-Loaded
      ObjectSet categories = Manager.GetObjectSet(typeof(Category), String.Empty);
      foreach (Category category in categories) {
        Console.WriteLine("Category {0}: {1}", category.Id, category.Desc);

        // Category and Contacts defined as a Many-To-Many Relationship
        foreach (Contact contact in category.Contacts) {
          Console.WriteLine("-- {0}: {1}", contact.Id, contact.Name);

          // Contacts and Details defined as a One-To-Many Relationship
          foreach (Detail detail in contact.Details) {

            // Details and Contacts defined as a Many-To-One Relationship
            // This is the Reverse which allows getting Contact from Detail
            // Note that Many-To-One can also be used for One-To-One Cases
            Console.WriteLine(" {0}: {1}", detail.Contact().Name, detail.Info);
            detail.Comment = "Update Each Child";
          }

          // PersistChanges with an ICollection is Transactional Persist
          // Note that you can create your own ICollection for Transactions
          Manager.PersistChanges(contact.Details);
        }
      }
    }
  }
}