comparison HowTo/Data/Prepare.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.Generic;
3
4 using NUnit.Framework;
5
6 using BLToolkit.Data;
7
8 namespace HowTo.Data
9 {
10 using DataAccess;
11
12 [TestFixture]
13 public class Prepare
14 {
15 [Test]
16 public void Test()
17 {
18 List<Person> list = new List<Person>
19 {
20 new Person { FirstName = "John", LastName = "Smith", Gender = Gender.Male },
21 new Person { FirstName = "Jane", LastName = "Smith", Gender = Gender.Female }
22 };
23
24 using (DbManager db = new DbManager())
25 {
26 db.BeginTransaction();
27
28 // Prepare command.
29 //
30 db
31 .SetSpCommand("Person_Insert",
32 db.CreateParameters(list[0]))
33 ./*[a]*/Prepare/*[/a]*/();
34
35 // Insert.
36 //
37 foreach (Person person in list)
38 {
39 db./*[a]*/AssignParameterValues/*[/a]*/(person);
40 db.ExecuteNonQuery();
41 }
42
43 // Check the result.
44 //
45 list = db
46 .SetCommand(
47 "SELECT * FROM Person WHERE LastName = @lastName",
48 db.Parameter("@lastName", "Smith"))
49 .ExecuteList<Person>();
50
51 Assert.GreaterOrEqual(2, list.Count);
52
53 // Cleanup.
54 //
55 db
56 .SetCommand(
57 "DELETE FROM Person WHERE LastName = @lastName",
58 db.Parameter("@lastName", "Smith"))
59 .ExecuteNonQuery();
60
61 db.CommitTransaction();
62 }
63 }
64 }
65 }