Skip to content

Commit 1235a38

Browse files
authored
Another example: Execute a command Multiple Times (#1690)
Another example for "Execute a command Multiple Times" when we have an existing collection. The existing example (which still remains) I found to be a little bit confusing when I had an existing collection. So hopefully this 2nd example will help a tiny bit.
1 parent 4aac41a commit 1235a38

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ var count = connection.Execute(@"insert MyTable(colA, colB) values (@a, @b)",
106106
);
107107
Assert.Equal(3, count); // 3 rows inserted: "1,1", "2,2" and "3,3"
108108
```
109+
110+
Another example usage when you _already_ have an existing collection:
111+
```csharp
112+
var foos = new List<Foo>
113+
{
114+
{ new Foo { A = 1, B = 1 } }
115+
{ new Foo { A = 2, B = 2 } }
116+
{ new Foo { A = 3, B = 3 } }
117+
};
118+
119+
var count = connection.Execute(@"insert MyTable(colA, colB) values (@a, @b)", foos);
120+
Assert.Equal(foos.Count, count);
121+
```
122+
109123
This works for any parameter that implements IEnumerable<T> for some T.
110124

111125
Performance

0 commit comments

Comments
 (0)