Mercurial > pub > bltoolkit
comparison HowTo/Data/ExecuteList.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Collections; | |
3 using System.Collections.Generic; | |
4 | |
5 using NUnit.Framework; | |
6 | |
7 using BLToolkit.Data; | |
8 using BLToolkit.Mapping; | |
9 using BLToolkit.Reflection; | |
10 | |
11 namespace HowTo.Data | |
12 { | |
13 [TestFixture] | |
14 public class ExecuteList | |
15 { | |
16 [MapValue(Gender.Female, "F")] | |
17 [MapValue(Gender.Male, "M")] | |
18 [MapValue(Gender.Unknown, "U")] | |
19 [MapValue(Gender.Other, "O")] | |
20 public enum Gender | |
21 { | |
22 Female, | |
23 Male, | |
24 Unknown, | |
25 Other | |
26 } | |
27 | |
28 [MapField("PersonID", "ID")] | |
29 public class Person | |
30 { | |
31 public int ID; | |
32 | |
33 public string LastName; | |
34 public string FirstName; | |
35 public string MiddleName; | |
36 public Gender Gender; | |
37 } | |
38 | |
39 IList<Person> GetPersonListSqlText() | |
40 { | |
41 using (DbManager db = new DbManager()) | |
42 { | |
43 return db | |
44 .SetCommand("SELECT * FROM Person") | |
45 ./*[a]*/ExecuteList<Person>()/*[/a]*/; | |
46 } | |
47 } | |
48 | |
49 [Test] | |
50 public void SqlText() | |
51 { | |
52 IList<Person> list = GetPersonListSqlText(); | |
53 | |
54 foreach (Person p in list) | |
55 TypeAccessor.WriteDebug(p); | |
56 } | |
57 | |
58 IList<Person> GetPersonListSproc() | |
59 { | |
60 using (DbManager db = new DbManager()) | |
61 { | |
62 return db | |
63 .SetSpCommand("Person_SelectAll") | |
64 ./*[a]*/ExecuteList<Person>()/*[/a]*/; | |
65 } | |
66 } | |
67 | |
68 [Test] | |
69 public void Sproc() | |
70 { | |
71 IList<Person> list = GetPersonListSproc(); | |
72 | |
73 foreach (Person p in list) | |
74 TypeAccessor.WriteDebug(p); | |
75 } | |
76 | |
77 void GetCustomPersonList(IList list) | |
78 { | |
79 using (DbManager db = new DbManager()) | |
80 { | |
81 db | |
82 .SetSpCommand("Person_SelectAll") | |
83 ./*[a]*/ExecuteList(list, typeof(Person))/*[/a]*/; | |
84 } | |
85 } | |
86 | |
87 [Test] | |
88 public void CustomList() | |
89 { | |
90 ArrayList list = new ArrayList(10); | |
91 | |
92 GetCustomPersonList(list); | |
93 | |
94 foreach (Person p in list) | |
95 TypeAccessor.WriteDebug(p); | |
96 } | |
97 } | |
98 } |