0
|
1 using System;
|
|
2 using System.Collections;
|
|
3 using System.Collections.Generic;
|
|
4
|
|
5 using NUnit.Framework;
|
|
6
|
|
7 using BLToolkit.DataAccess;
|
|
8
|
|
9 namespace HowTo.DataAccess
|
|
10 {
|
|
11 [TestFixture]
|
|
12 public class ExecuteList
|
|
13 {
|
|
14 public abstract class /*[a]*/PersonAccessor/*[/a]*/ : /*[a]*/DataAccessor/*[/a]*/
|
|
15 {
|
|
16 // This method reads a list of Person objects.
|
|
17 //
|
|
18 [ActionName("SelectAll")]
|
|
19 public abstract /*[a]*/List<Person>/*[/a]*/ GetPersonList1();
|
|
20
|
|
21 // Here we help the method to get object type information.
|
|
22 // /*[a]*/ObjectTypeAttribute/*[/a]*/ can be applied to the class itself.
|
|
23 // In this case there is no need to specify object type for each method.
|
|
24 // Another way to specify object type is a generic parameter
|
|
25 // of the DataAccessor<T> class.
|
|
26 //
|
|
27 [SqlQuery("SELECT * FROM Person")]
|
|
28 [/*[a]*/ObjectType(typeof(Person))/*[/a]*/]
|
|
29 public abstract /*[a]*/ArrayList/*[/a]*/ GetPersonList2();
|
|
30
|
|
31 // This method reads a list of scalar values.
|
|
32 //
|
|
33 [SqlQuery("SELECT PersonID FROM Person")]
|
|
34 public abstract /*[a]*/List<int>/*[/a]*/ GetPersonIDList();
|
|
35 }
|
|
36
|
|
37 [Test]
|
|
38 public void Test()
|
|
39 {
|
|
40 PersonAccessor pa = DataAccessor.CreateInstance<PersonAccessor>();
|
|
41
|
|
42 // ExecuteList.
|
|
43 //
|
|
44 IList list;
|
|
45
|
|
46 list = pa.GetPersonList1();
|
|
47 list = pa.GetPersonList2();
|
|
48
|
|
49 foreach (Person p in list)
|
|
50 Console.WriteLine("{0}: {1} {2}", p.ID, p.FirstName, p.LastName);
|
|
51
|
|
52 // ExecuteScalarList.
|
|
53 //
|
|
54 List<int> slist = pa.GetPersonIDList();
|
|
55
|
|
56 foreach (int id in slist)
|
|
57 Console.WriteLine("{0}", id);
|
|
58 }
|
|
59 }
|
|
60 }
|