Lookup Table Objects

 

 

Lookup Tables are defined within the ORM.NET Object Browser for a given table object by enabling the Is Lookup Table checkbox as shown below.

 

 

 

 

 

 

By setting a table object as a Lookup you designate that the data wrapped by the object will be read-only. The effect of this is that the generated Data Layer will not create any Add[Object], New[Object], or Delete[Object] method signatures nor will any of the column properties have Set Mutators. Therefore, Lookup objects are appropriate in cases where you know the data is mostly static. The benefit of using Lookup objects within your application is that because the data is read-only it can be managed as a separate DataSet and cached once to be shared by multiple threads or users to improve performance. You can define as many table objects as Lookup objects as you require. 

 

All Lookup table object data access is managed by a sub-classed version of the DataManager object contained within a separate DataSet.

 

Lookup Examples

 

The following examples assume the Course table object has been set as a Lookup object as shown above.

 

Remember that for these changes to take effect you must regenerate the Data Layer  by clicking the 'Generate Data Layer' button within ORM.NET and then re-compile the Data Layer solution within Visual Studio.NET.

 

 

C#

 

// Create a new Lookup object – a sub-classed DataManager

Lookups lookup = new Lookups(Config.Dsn);

                 

// find a specific course and assign a local object reference

Course course = lookup.Courses.FindByClassName("History 101");

 

// Display some property information about the Course retrieved from the cached Lookup object

Console.WriteLine("Course " + course.ClassName + " " + course.ID);

 

 

Visual Basic.NET

 

' Create a new Lookup object – a sub-classed DataManager

Dim lookup as New Lookups(Config.Dsn)

                 

' Find a specific course and assign a local object reference

Dim course As New Course = lookup.Courses.FindByClassName("History 101")

 

' Display some property information about the Course retrieved from the cached Lookup object

Console.WriteLine("Course " + course.ClassName + " " + course.ID)

 

 

The next example uses a collection to work with the entire set of data within the Course object.

 

C#

 

// Assign a local Course Collection

CourseCollection courses = lookup.Courses;

 

// loop through each record in the Course table

foreach(Course c in courses)

Console.WriteLine("Course Name: " + c.ClassName);

 

//Create new Course collection with filter applied on the DateCreated property

CourseCollection oldcourses = courses.FilterByDateCreated(DateTime.Parse("11/06/2002"));

 

   

Visual Basic.NET

 

' Assign a local Course Collection

Dim courses As CourseCollection = lookup.Courses

 

' loop through each record in the Course table

 

Dim c As Course

For Each c in courses

Console.WriteLine("Course Name: " + c.ClassName)

Next

 

' Create new Course collection with filter applied on the DateCreated property

Dim oldcourses As CourseCollection = courses.FilterByDateCreated(DateTime.Parse("11/06/2002"))

 

              

 

This example shows how you can use Lookup objects to create a new Parent object and assign a value retrieved from the Lookup cache.

 

C#

 

Lookups lookups = new Lookups(Config.Dsn);

 

Schedule s = dm.NewSchedule();  // Create a new Schedule object

 

// assign the Schedule object to the desired Course object (Parent)

s.Course = lookups.Courses.FindByClassName("History 101");

 

//.. add the rest of the schedule information

 

dm.CommitAll(); // create the Schedule object with the Parent Course information

 

 

Visual Basic.NET

 

Dim lookups As New Lookups(Config.Dsn)

 

Dim s As Schedule = dm.NewSchedule();  ' Create a new Schedule object

 

' assign the Schedule object to the desired Course object (Parent)

s.Course = lookups.Courses.FindByClassName("History 101")

 

'.. add the rest of the schedule information

 

dm.CommitAll()  ' create the Schedule object with the Parent Course information

 

 

Another common task that Lookup objects are used for is to bind them to Drop down lists. The last example shows how to bind the list of available Courses to appear in a drop-down list.

 

 

Lookups lookups = new Lookups(Config.Dsn);

 

// Courses is set as the DataSource - Courses is returned sorted by ID in ascending order.

DropDownListCourses.DataSource = lookups.Courses.SortByID(SortDirection.Ascending);

 

DropDownListCourses.DataBind();  // bind the data source

           

 

Lookup.ReRefreshLookups() is used to refresh the data within the Lookup object DataSet if another process updates the data. This will force a retrieval of the data from the database and repopulate the cache for the tables.

 

 

See Table Object Settings for more information on how to set Table objects to be Lookup objects.