Skip to content

Commit 313fe71

Browse files
committed
Introduced new AttributeValuesDataTable class
The new `AttributeValuesDataTable` centralizes the definition of the `AttributeValues` table-valued type from the SQL Server database schema, and exposes a convenience method for constructing new records.
1 parent 3fd9720 commit 313fe71

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using System.Data;
7+
8+
namespace OnTopic.Data.Sql.Models {
9+
10+
/*============================================================================================================================
11+
| CLASS: ATTRIBUTE VALUES (DATA TABLE)
12+
\---------------------------------------------------------------------------------------------------------------------------*/
13+
/// <summary>
14+
/// Extends <see cref="DataTable"/> to model the schema for the <c>AttributeValues</c> user-defined table type.
15+
/// </summary>
16+
public class AttributeValuesDataTable: DataTable {
17+
18+
/*==========================================================================================================================
19+
| CONSTRUCTOR
20+
\-------------------------------------------------------------------------------------------------------------------------*/
21+
/// <summary>
22+
/// Establishes a new <see cref="DataTable"/> with the appropriate schema for the <c>AttributeValues</c> user-defined
23+
/// table type.
24+
/// </summary>
25+
public AttributeValuesDataTable() {
26+
27+
/*------------------------------------------------------------------------------------------------------------------------
28+
| COLUMN: Attribute Key
29+
\-----------------------------------------------------------------------------------------------------------------------*/
30+
Columns.Add(
31+
new DataColumn("AttributeKey") {
32+
MaxLength = 128
33+
}
34+
);
35+
36+
/*------------------------------------------------------------------------------------------------------------------------
37+
| COLUMN: Attribute Value
38+
\-----------------------------------------------------------------------------------------------------------------------*/
39+
Columns.Add(
40+
new DataColumn("AttributeValue") {
41+
MaxLength = 255
42+
}
43+
);
44+
45+
}
46+
47+
/*==========================================================================================================================
48+
| ADD ROW
49+
\-------------------------------------------------------------------------------------------------------------------------*/
50+
/// <summary>
51+
/// Provides a convenience method for adding a new <see cref="DataRow"/> based on the expected column values.
52+
/// </summary>
53+
public DataRow AddRow(string attributeKey, string? attributeValue = null) {
54+
55+
/*------------------------------------------------------------------------------------------------------------------------
56+
| Define record
57+
\-----------------------------------------------------------------------------------------------------------------------*/
58+
var record = NewRow();
59+
record["AttributeKey"] = attributeKey;
60+
record["AttributeValue"] = attributeValue;
61+
62+
/*------------------------------------------------------------------------------------------------------------------------
63+
| Add record
64+
\-----------------------------------------------------------------------------------------------------------------------*/
65+
Rows.Add(record);
66+
67+
/*------------------------------------------------------------------------------------------------------------------------
68+
| Return record
69+
\-----------------------------------------------------------------------------------------------------------------------*/
70+
return record;
71+
72+
}
73+
74+
} //Class
75+
} //Namespaces

0 commit comments

Comments
 (0)