comparison HowTo/Data/ExecuteForEach.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 ExecuteForEach
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 // Execute.
29 //
30 db
31 .SetSpCommand("Person_Insert")
32 ./*[a]*/ExecuteForEach/*[/a]*/<Person>(list);
33
34 // Check the result.
35 //
36 list = db
37 .SetCommand(
38 "SELECT * FROM Person WHERE LastName = @lastName",
39 db.Parameter("@lastName", "Smith"))
40 .ExecuteList<Person>();
41
42 Assert.GreaterOrEqual(2, list.Count);
43
44 // Cleanup.
45 //
46 db
47 .SetCommand(
48 "DELETE FROM Person WHERE LastName = @lastName",
49 db.Parameter("@lastName", "Smith"))
50 .ExecuteNonQuery();
51
52 db.CommitTransaction();
53 }
54 }
55 }
56 }