comparison HowTo/Data/ExecuteObject.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
3 using NUnit.Framework;
4
5 using BLToolkit.Data;
6 using BLToolkit.Mapping;
7 using BLToolkit.Reflection;
8
9 namespace HowTo.Data
10 {
11 [TestFixture]
12 public class ExecuteObject
13 {
14 public enum Gender
15 {
16 [MapValue("F")] Female,
17 [MapValue("M")] Male,
18 [MapValue("U")] Unknown,
19 [MapValue("O")] Other
20 }
21
22 public abstract class Person
23 {
24 [MapField("PersonID")]
25 public abstract int ID { get; }
26
27 public abstract string LastName { get; set; }
28 public abstract string FirstName { get; set; }
29 public abstract string MiddleName { get; set; }
30 public abstract Gender Gender { get; set; }
31 }
32
33 Person GetPersonSqlText(int id)
34 {
35 using (DbManager db = new DbManager())
36 {
37 return db
38 .SetCommand("SELECT * FROM Person WHERE PersonID = @id",
39 db.Parameter("@id", id))
40 ./*[a]*/ExecuteObject<Person>()/*[/a]*/;
41 }
42 }
43
44 [Test]
45 public void SqlText()
46 {
47 Person person = GetPersonSqlText(1);
48
49 TypeAccessor.WriteConsole(person);
50 }
51
52 Person GetPersonSproc1(int id)
53 {
54 using (DbManager db = new DbManager())
55 {
56 return db
57 .SetSpCommand("Person_SelectByKey",
58 db.Parameter("@id", id))
59 ./*[a]*/ExecuteObject<Person>()/*[/a]*/;
60 }
61 }
62
63 [Test]
64 public void Sproc1()
65 {
66 Person person = GetPersonSproc1(1);
67
68 TypeAccessor.WriteConsole(person);
69 }
70
71 Person GetPersonSproc2(int id)
72 {
73 using (DbManager db = new DbManager())
74 {
75 return db
76 .SetSpCommand("Person_SelectByKey", id)
77 ./*[a]*/ExecuteObject<Person>()/*[/a]*/;
78 }
79 }
80
81 [Test]
82 public void Sproc2()
83 {
84 Person person = GetPersonSproc2(1);
85
86 TypeAccessor.WriteConsole(person);
87 }
88 }
89 }