-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (38 loc) · 1.74 KB
/
Program.cs
File metadata and controls
42 lines (38 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection;
namespace SQLHelper.Example
{
/// <summary>
/// This is an example program that shows how to use the SQLHelper.DB library to execute a batch of queries.
/// </summary>
internal class Program
{
/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
private static async Task Main(string[] args)
{
// Start by creating a new ServiceCollection and adding the Canister modules to it (this will also add the SQLHelper module)
var Services = new ServiceCollection().AddCanisterModules()?.BuildServiceProvider();
// Get the SQLHelper instance from the ServiceCollection
var Helper = Services.GetService<SQLHelperDB.SQLHelper>();
// Execute a batch of queries and return the results (this will return a list of lists of rows. The first list contains the results of each query. The inner lists contain the rows.)
var Results = await Helper.CreateBatch(SqlClientFactory.Instance)
.AddQuery(System.Data.CommandType.Text, "SELECT * FROM [dbo].[TestTable]")
.AddQuery(System.Data.CommandType.Text, "SELECT * FROM [dbo].[TestTable]")
.ExecuteAsync()
.ConfigureAwait(false);
// Go through each result
foreach (var Result in Results)
{
// Go through each row in the result
foreach (var Row in Result)
{
// Write the row to the console
Console.WriteLine(Row.ToString());
}
}
}
}
}