-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
141 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<!DOCTYPE html> | ||
<!-- Copyright (c) Lester J. Clark and Contributors. --> | ||
<!-- Licensed under the MIT License. --> | ||
<!-- DALTestAdd.html --> | ||
<html> | ||
<head> | ||
<title>Data Test Add</title> | ||
<link rel="stylesheet" type="text/css" href="../CSS/CodeDoc.css" /> | ||
<link rel="stylesheet" type="text/css" href="../CSS/HTMLBooks.css" /> | ||
<link rel='stylesheet' type='text/css' href='../CSS/Syntax.css' /> | ||
</head> | ||
<body> | ||
<div class="page"> | ||
<a href="DALTestLoad.html">The DAL Test Add() Method</a> | ||
<br /> | ||
<h3 class="headingMargin">The Add() Method</h3> | ||
<!-- ******************************* --> | ||
<div class="columns"> | ||
<p class="book"> | ||
The inherited PersonManager.Add() method adds a new record to the | ||
configured table. | ||
</p> | ||
<h4 class="headingMargin">Database Assigned Values</h4> | ||
<p class="book"> | ||
The Add() method has some unique functionality to handle database assigned | ||
values. These are values that are assigned by the database when a column | ||
is defined as AutoIncrement or by a database trigger. | ||
</p> | ||
<ul class="listMargin"> | ||
<li> | ||
Add the "GetKey Methods" region to the PersonManager class. | ||
</li> | ||
<li> | ||
Add the SetExcludeKeys() method to the PersonManager class, "GetKey | ||
Methods" region. | ||
</li> | ||
</ul> | ||
</div> | ||
<pre class="code"> | ||
#region GetKey Methods | ||
|
||
// Sets the temporary exclude keys. | ||
/// <include path='items/SetExcludeKeys/*' file='../../CommonManager.xml' /> | ||
public void SetExcludeKeys() | ||
{ | ||
string[] excludeNames = new string[] | ||
{ | ||
Person.ColumnPrincipleFlag | ||
}; | ||
SetExcludeKeyValues(excludeNames); | ||
} | ||
#endregion</pre> | ||
<!-- ******************************* --> | ||
<div class="columnsAuto"> | ||
<ul class="listMargin"> | ||
<li> | ||
Add the TestAdd() function to the Program class, "TestFunctions" region. | ||
</li> | ||
</ul> | ||
</div> | ||
<pre class="code"> | ||
// Test the Add function. | ||
private static void TestAdd(PersonManager personManager) | ||
{ | ||
Console.WriteLine(); | ||
Console.WriteLine("TestAdd"); | ||
|
||
// Delete existing "Added" record to allow for new Add. | ||
Person keyRecord = new Person() | ||
{ | ||
Name = "Added" | ||
}; | ||
personManager.SetExcludeKeys(); | ||
Person lookupRecord = personManager.Retrieve(keyRecord); | ||
if (lookupRecord != null) | ||
{ | ||
personManager.SetExcludeKeys(); | ||
personManager.Delete(keyRecord); | ||
} | ||
|
||
// Add record | ||
Person dataRecord = new Person() | ||
{ | ||
Name = "Added", | ||
PrincipleFlag = false | ||
}; | ||
Person addedRecord = personManager.Add(dataRecord); | ||
if (addedRecord != null) | ||
{ | ||
dataRecord.ID = addedRecord.ID; | ||
WriteRowString(dataRecord); | ||
} | ||
}</pre> | ||
<!-- ******************************* --> | ||
<div class="columns"> | ||
<ul class="listMargin"> | ||
<li> | ||
Add the TestAdd(personManager) function call to the Program class, "Test function calls." section. | ||
</li> | ||
</ul> | ||
</div> | ||
<h4 class="headingMargin">The Key Record Object</h4> | ||
<!-- ******************************* --> | ||
<div class="columns"> | ||
<p class="book"> | ||
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. | ||
</p> | ||
<p class="book"> | ||
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. | ||
</p> | ||
<p class="book"> | ||
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. | ||
</p> | ||
</div> | ||
<pre class="code"> | ||
select ID, Name, PrincipleFlag | ||
from Person | ||
where Name = 'Added' and PrincipleFlag = '0'.</pre> | ||
<div class="columns"> | ||
<p class="book"> | ||
To prevent the PrincipleFlag value from being included in the SQL | ||
statement, we first call the SetExcludeKeys() method. | ||
</p> | ||
<p class="book"> | ||
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. | ||
</p> | ||
</div> | ||
<br /> | ||
<a href="DALTestRetrieve.html">The DAL Test Retrieve() Method</a> | ||
</div> | ||
</body> | ||
</html> |