0
|
1 <% group # Abstract accessors %>
|
|
2 <% order # 20 %>
|
|
3
|
|
4 <p class="j">The following example demonstrates how to create and use an abstract data accessor class.
|
|
5 All abstract methods of the class are generated at run-time depending on each method declaration.
|
|
6 Every part of the method declaration is important.
|
|
7 Method's return value specifies one of the Execute methods in the following way:
|
|
8 <table class='data'>
|
|
9 <tr><th>Return Type</th><th>Execute Method</th></tr>
|
|
10 <tr><td><i>IDataReader</i> interface</td><td>ExecuteReader</td></tr>
|
|
11 <tr><td>Subclass of <i>DataSet</i></td><td>ExecuteDataSet</td></tr>
|
|
12 <tr><td>Subclass of <i>DataTable</i></td><td>ExecuteDataTable</td></tr>
|
|
13 <tr><td>Class implementing the <i>IList</i> interface</td><td><a href="ExecuteList.htm">ExecuteList</a> or <a href="ExecuteList.htm">ExecuteScalarList</a></td></tr>
|
|
14 <tr><td>Class implementing the <i>IDictionary</i> interface</td><td><a href="ExecuteDictionary.htm">ExecuteDictionary</a> or <a href="ExecuteDictionary.htm">ExecuteScalarDictionary</a></td></tr>
|
|
15 <tr><td><i>void</i></td><td>ExecuteNonQuery</td></tr>
|
|
16 <tr><td><i>string</i>, <i>byte[]</i> or value type</td><td><a href="ExecuteScalar.htm">ExecuteScalar</a></td></tr>
|
|
17 <tr><td>In any other case</td><td><a href="ExecuteObject.htm">ExecuteObject</a></td></tr>
|
|
18 </table>
|
|
19 Method name explicitly defines action name which is converted to stored procedure name.<br/>
|
|
20 Type, sequential order, and name of the method parameters is mapped to the command parameters.
|
|
21 Exceptions from this rule are:
|
|
22 <br>
|
|
23 <div style="margin:-10px 0px -10px -10px"><ul compact="compact">
|
|
24 <li>a parameter of <a href="../Data/index.htm"><i>DbManager</i></a> type. In this case generator uses provided <a href="../Data/index.htm"><i>DbManager</i></a> to call the command.</li>
|
|
25 <li>parameters decorated with attribute <i>FormatAttribute</i>.</li>
|
|
26 </ul></div>
|
|
27 </p>
|
|
28 AbstractAccessor.cs
|
|
29 <% ..\..\..\HowTo\DataAccess\AbstractAccessor.cs %>
|
|
30 <a name='Person'></a>
|
|
31 Person.cs
|
|
32 <% ..\..\..\HowTo\DataAccess\Person.cs %>
|
|
33 Gender.cs
|
|
34 <% ..\..\..\HowTo\DataAccess\Gender.cs %>
|
|
35 App.config
|
|
36 <% Doc\Data\App.config %>
|
|
37 <a href="../Data/CreateSql.htm">Create.sql script</a>
|