-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathReadme - Light.html
191 lines (171 loc) · 18.1 KB
/
Readme - Light.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html><head><META http-equiv=Content-Type content="text/html; charset=UTF-8"><title>EntityJustWorks.SQL Documentation</title><style type="text/css">body { font-family: 'Consolas'; font-size: 11pt; color: #657B83; background: #FDF6E3;}
.c1 {color: #859900;}
.c2 {color: #2AA198;}
.c3 {color: #586E75;}
.c4 {font-style: italic; color: #93A1A1;}
.c5 {color: #B58900;}</style></head><body><div style="float: left; white-space: pre; line-height: 1;"><span class="c1">namespace</span> EntityJustWorks<span class="c3">.</span>SQL
<span class="c3">{</span>
<span class="c4">/// <summary>
Convert to and from a CLR class instance
</summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">class</span> ClassInstance
<span class="c3">{</span>
<span class="c4">/// <summary>
/// Generates the C# class code from a DataTable.
/// </summary>
/// <returns>The C# class code as a string.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> FileInfo ToCSharpCode<span class="c3"><</span>T<span class="c3">>(</span><span class="c5">string</span> customSavePath <span class="c3">=</span> <span class="c2">"{Namespace}.{Class}.cs"</span><span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Emits a C# Assembly with classes whos public properties match the columns of the DataTable.
/// </summary>
/// <returns>The C# Type for the emitted class</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> Type ToAssembly<span class="c3"><</span>T<span class="c3">>()</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Creates a DataTable from a class type's public properties and adds a new DataRow to the table for each class passed as a parameter.
/// The DataColumns of the table will match the name and type of the public properties.
/// </summary>
/// <param name="classInstanceCollection">A class or array of class to fill the DataTable with.</param>
/// <returns>A DataTable who's DataColumns match the name and type of each class T's public properties.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable ToDataTable<span class="c3"><</span>T<span class="c3">>(</span><span class="c1">params</span> T<span class="c3">[]</span> classInstanceCollection<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Creates a DataTable from a class type's public properties. The DataColumns of the table will match the name and type of the public properties.
/// </summary>
/// <typeparam name="T">The type of the class to create a DataTable from.</typeparam>
/// <returns>A DataTable who's DataColumns match the name and type of each class T's public properties.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable ToDataTable<span class="c3"><</span>T<span class="c3">>()</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Executes an SQL query and returns the results as a DataTable.
/// </summary>
/// <param name="connectionString">The SQL connection string.</param>
/// <param name="formatString_Query">A SQL command that will be passed to string.Format().</param>
/// <param name="formatString_Parameters">The parameters for string.Format().</param>
/// <returns>The results of the query as a DataTable.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> IList<span class="c3"><</span>T<span class="c3">></span> FromQuery<span class="c3"><</span>T<span class="c3">>(</span><span class="c5">string</span> connectionString<span class="c3">,</span> <span class="c5">string</span> formatString_Query<span class="c3">,</span> <span class="c1">params</span> <span class="c1">object</span><span class="c3">[]</span> formatString_Parameters<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span><span class="c3">,</span> <span class="c1">new</span><span class="c3">()</span>
<span class="c4">/// <summary>
/// Fills properties of a class from a row of a DataTable where the name of the property matches the column name from that DataTable.
/// It does this for each row in the DataTable, returning a List of classes.
/// </summary>
/// <typeparam name="T">The class type that is to be returned.</typeparam>
/// <param name="Table">DataTable to fill from.</param>
/// <returns>A list of ClassType with its properties set to the data from the matching columns from the DataTable.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> IList<span class="c3"><</span>T<span class="c3">></span> FromDataTable<span class="c3"><</span>T<span class="c3">>(</span>DataTable dataTable<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span><span class="c3">,</span> <span class="c1">new</span><span class="c3">()</span>
<span class="c3">{</span>
<span class="c1">return</span> Table<span class="c3">.</span>ToClassInstanceCollection<span class="c3"><</span>T<span class="c3">>(</span>dataTable<span class="c3">);</span>
<span class="c3">}</span>
<span class="c3">}</span>
<span class="c4">/// <summary>
SQL Query Helper Class
</summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">class</span> DatabaseQuery
<span class="c3">{</span>
<span class="c4">/// <summary>
/// Runs a SQL query and returns the results as a List of the specified class
/// </summary>
/// <typeparam name="T">The type the result will be returned as.</typeparam>
/// <param name="connectionString">The SQL connection string.</param>
/// <param name="formatString_Query">A SQL command that will be passed to string.Format().</param>
/// <param name="formatString_Parameters">The parameters for string.Format().</param>
/// <returns>A List of classes that represent the records returned.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> IList<span class="c3"><</span>T<span class="c3">></span> ToClass<span class="c3"><</span>T<span class="c3">>(</span><span class="c5">string</span> connectionString<span class="c3">,</span> <span class="c5">string</span> formatString_Query<span class="c3">,</span> <span class="c1">params</span> <span class="c1">object</span><span class="c3">[]</span> formatString_Parameters<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span><span class="c3">,</span> <span class="c1">new</span><span class="c3">()</span>
<span class="c4">/// <summary>
/// Executes an SQL query and returns the results as a DataTable.
/// </summary>
/// <param name="connectionString">The SQL connection string.</param>
/// <param name="formatString_Query">A SQL command that will be passed to string.Format().</param>
/// <param name="formatString_Parameters">The parameters for string.Format().</param>
/// <returns>The results of the query as a DataTable.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable ToDataTable<span class="c3">(</span><span class="c5">string</span> connectionString<span class="c3">,</span> <span class="c5">string</span> formatString_Query<span class="c3">,</span> <span class="c1">params</span> <span class="c1">object</span><span class="c3">[]</span> formatString_Parameters<span class="c3">)</span>
<span class="c4">/// <summary>
/// Executes a non-query SQL command, such as INSERT or DELETE
/// </summary>
/// <param name="connectionString">The connection string.</param>
/// <param name="FormatString_Command">The SQL command, as a format string.</param>
/// <param name="formatString_Parameters">The parameters for the format string.</param>
/// <returns>The number of rows affected, or -1 on errors.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">int</span> NonQueryCommand<span class="c3">(</span><span class="c5">string</span> connectionString<span class="c3">,</span> <span class="c5">string</span> FormatString_Command<span class="c3">,</span> <span class="c1">params</span> <span class="c1">object</span><span class="c3">[]</span> formatString_Parameters<span class="c3">)</span>
<span class="c4">/// <summary>
/// Executes a query, and returns the first column of the first row in the result set returned by the query.
/// </summary>
/// <typeparam name="T">The type the result will be returned as.</typeparam>
/// <param name="connectionString">>The SQL connection string.</param>
/// <param name="formatString_Query">The SQL query as string.Format string.</param>
/// <param name="formatString_Parameters">The string.Format parameters.</param>
/// <returns>The first column of the first row in the result, converted and casted to type T.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> T ToScalarValue<span class="c3"><</span>T<span class="c3">>(</span><span class="c5">string</span> connectionString<span class="c3">,</span> <span class="c5">string</span> formatString_Query<span class="c3">,</span> <span class="c1">params</span> <span class="c1">object</span><span class="c3">[]</span> formatString_Parameters<span class="c3">)</span>
<span class="c3">}</span>
<span class="c4">/// <summary>
SQL Script Generation Class
</summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">class</span> SQLScript
<span class="c3">{</span>
<span class="c4">/// <summary>
/// Creates a SQL script that inserts the values of the specified classes' public properties into a table.
/// </summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">string</span> InsertInto<span class="c3"><</span>T<span class="c3">>(</span><span class="c1">params</span> T<span class="c3">[]</span> ClassObjects<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Creates a SQL script that inserts the cell values of a DataTable's DataRows into a table.
/// </summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">string</span> InsertInto<span class="c3">(</span>DataTable Table<span class="c3">)</span>
<span class="c4">/// <summary>
/// Creates a SQL script that creates a table where the column names match the specified class's public properties.
/// </summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">string</span> CreateTable<span class="c3"><</span>T<span class="c3">>(</span><span class="c1">params</span> T<span class="c3">[]</span> ClassObjects<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Creates a SQL script that creates a table where the columns matches that of the specified DataTable.
/// </summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">string</span> CreateTable<span class="c3">(</span>DataTable Table<span class="c3">)</span>
<span class="c3">}</span>
<span class="c4">/// <summary>
Convert to and from a System.Data.DataTable
</summary>
</span> <span class="c1">public</span> <span class="c5">static</span> <span class="c5">class</span> Table
<span class="c3">{</span>
<span class="c4">/// <summary>
/// Creates a DataTable from a class type's public properties and adds a new DataRow to the table for each class passed as a parameter.
/// The DataColumns of the table will match the name and type of the public properties.
/// </summary>
/// <param name="classInstanceCollection">A class or array of class to fill the DataTable with.</param>
/// <returns>A DataTable who's DataColumns match the name and type of each class T's public properties.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable FromClassInstanceCollection<span class="c3"><</span>T<span class="c3">>(</span><span class="c1">params</span> T<span class="c3">[]</span> classInstanceCollection<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Creates a DataTable from a class type's public properties. The DataColumns of the table will match the name and type of the public properties.
/// </summary>
/// <typeparam name="T">The type of the class to create a DataTable from.</typeparam>
/// <returns>A DataTable who's DataColumns match the name and type of each class T's public properties.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable FromClass<span class="c3"><</span>T<span class="c3">>()</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Adds a DataRow to a DataTable from the public properties of a class.
/// </summary>
/// <param name="dataTable">A reference to the DataTable to insert the DataRow into.</param>
/// <param name="classObject">The class containing the data to fill the DataRow from.</param>
/// <returns>The DataTable in the parameters. This return instance is superflowous; </returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable FromClassInstance<span class="c3"><</span>T<span class="c3">>(</span>DataTable dataTable<span class="c3">,</span> T classObject<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span>
<span class="c4">/// <summary>
/// Fills properties of a class from a row of a DataTable where the name of the property matches the column name from that DataTable.
/// It does this for each row in the DataTable, returning a List of classes.
/// </summary>
/// <typeparam name="T">The class type that is to be returned.</typeparam>
/// <param name="dataTable">DataTable to fill from.</param>
/// <returns>A list of ClassType with its properties set to the data from the matching columns from the DataTable.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> IList<span class="c3"><</span>T<span class="c3">></span> ToClassInstanceCollection<span class="c3"><</span>T<span class="c3">>(</span>DataTable dataTable<span class="c3">)</span> where T <span class="c3">:</span> <span class="c5">class</span><span class="c3">,</span> <span class="c1">new</span><span class="c3">()</span>
<span class="c4">/// <summary>
/// Executes an SQL query and returns the results as a DataTable.
/// </summary>
/// <param name="connectionString">The SQL connection string.</param>
/// <param name="formatString_Query">A SQL command that will be passed to string.Format().</param>
/// <param name="formatString_Parameters">The parameters for string.Format().</param>
/// <returns>The results of the query as a DataTable.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> DataTable FromQuery<span class="c3">(</span><span class="c5">string</span> connectionString<span class="c3">,</span> <span class="c5">string</span> formatString_Query<span class="c3">,</span> <span class="c1">params</span> <span class="c1">object</span><span class="c3">[]</span> formatString_Parameters<span class="c3">)</span>
<span class="c4">/// <summary>
/// Generates the C# class code from a DataTable.
/// </summary>
/// <returns>The C# class code as a string.</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> FileInfo ToCSharpCode<span class="c3">(</span>DataTable dataTable<span class="c3">,</span> <span class="c5">string</span> customSavePath <span class="c3">=</span> <span class="c2">"{Namespace}.{Class}.cs"</span><span class="c3">)</span>
<span class="c4">/// <summary>
/// Emits a C# Assembly with classes whos public properties match the columns of the DataTable.
/// </summary>
/// <returns>The C# Type for the emitted class</returns>
</span> <span class="c1">public</span> <span class="c5">static</span> Type ToAssembly<span class="c3">(</span>DataTable dataTable<span class="c3">)</span>
<span class="c3">}</span>
<span class="c3">}</span></div></body></html>