The inherited PersonManager.Retrieve() method retrieves a single record that matches the key specified by the keyRecord parameter.
#region GetKey Methods // Sets the temporary exclude keys. /// public void SetExcludeKeys() { string[] excludeNames = new string[] { Person.ColumnPrincipleFlag }; SetExcludeKeyValues(excludeNames); } #endregion
The key record data object is used to modify a data method to restrict it to those records that match the key record initialized properties.
There are some properties that are automatically initialized in a data object. These are properties such as numeric and DateTime. Numeric properties are automatically initialized to zero.
If we create a Person key record and set the Name property, the PrincipleFlag property is automatically initialized to zero. This causes the personManager.Retrieve(keyRecord) method to internally create the following SQL statement.
select ID, Name, PrincipleFlag from Person where Name = 'Added' and PrincipleFlag = '0'.
To prevent the PrincipleFlag value from being included in the SQL statement, we first call the SetExcludeKeys() method.
The SetExcludeKeys() manager method is used to temporarily exclude specific fields from the SQL statement created from the KeyRecord object. The manager exclude keys are cleared after a call to any data access method.
// Test the Retrieve function. private static void TestRetrieve(PersonManager personManager) { Console.WriteLine(); Console.WriteLine("TestRetrieve"); Person keyRecord = new Person() { Name = "Added" }; personManager.SetExcludeKeys(); Person lookupRecord = personManager.Retrieve(keyRecord); if (lookupRecord != null) { WriteRowString(lookupRecord); } }
if (success) { // Test function calls. TestLoad(personManager); TestAdd(personManager); TestRetrieve(personManager); Console.WriteLine("Press any key to continue . . ."); Console.ReadKey(); }