Skip to content

Commit 3c41dfe

Browse files
committed
Adjusted samples
1 parent b9db523 commit 3c41dfe

File tree

2 files changed

+21
-18
lines changed
  • samples
    • Thinktecture.EntityFrameworkCore.SqlServer.Samples
    • Thinktecture.EntityFrameworkCore.Sqlite.Samples

2 files changed

+21
-18
lines changed

samples/Thinktecture.EntityFrameworkCore.SqlServer.Samples/Program.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public static async Task Main(string[] args)
2525
ctx.ChangeTracker.Clear(); // resetting DbContext, as an alternative to create a new one
2626

2727
// Bulk insert into "real" tables
28-
await DoBulkInsertIntoRealTableAsync(ctx);
28+
await DoBulkInsertAsync(ctx);
2929
ctx.ChangeTracker.Clear();
3030

31-
await DoBulkInsertSpecifiedColumnsIntoRealTableAsync(ctx);
31+
await DoBulkInsertSpecificColumnsAsync(ctx);
3232
ctx.ChangeTracker.Clear();
3333

3434
// Bulk update
@@ -43,18 +43,21 @@ public static async Task Main(string[] args)
4343
await DoBulkDeleteAsync(ctx);
4444
ctx.ChangeTracker.Clear();
4545

46-
await DoScalarCollectionParameterAsync(ctx, new List<Guid> { customerId });
47-
await DoComplexCollectionParameterAsync(ctx, customerId);
46+
// Bulk insert into temp tables
47+
await DoBulkInsertIntoTempTableAsync(ctx, new List<Guid> { customerId });
4848
ctx.ChangeTracker.Clear();
4949

50-
// Bulk insert into temp tables
51-
await DoBulkInsertEntitiesIntoTempTableAsync(ctx);
50+
await DoBulkInsertIntoTempTableAsync(ctx, new List<(Guid, Guid)> { (customerId, productId) });
5251
ctx.ChangeTracker.Clear();
5352

54-
await DoBulkInsertIntoTempTableAsync(ctx, new List<Guid> { customerId });
53+
await DoBulkInsertIntoTempTableAsync(ctx);
5554
ctx.ChangeTracker.Clear();
5655

57-
await DoBulkInsertIntoTempTableAsync(ctx, new List<(Guid, Guid)> { (customerId, productId) });
56+
// Collection parameter
57+
await DoScalarCollectionParameterAsync(ctx, new List<Guid> { customerId });
58+
ctx.ChangeTracker.Clear();
59+
60+
await DoComplexCollectionParameterAsync(ctx, customerId);
5861
ctx.ChangeTracker.Clear();
5962

6063
// LEFT JOIN
@@ -90,7 +93,7 @@ private static async Task DoComplexCollectionParameterAsync(DemoDbContext ctx, G
9093
{
9194
var parameters = ctx.CreateComplexCollectionParameter(new[] { new MyParameter(customerId, 42) });
9295

93-
var customers = await ctx.Customers.Join(parameters, c => c.Id, t => t.Column1, (c, t) => new { Customer = c, Number = t.Column2}).ToListAsync();
96+
var customers = await ctx.Customers.Join(parameters, c => c.Id, t => t.Column1, (c, t) => new { Customer = c, Number = t.Column2 }).ToListAsync();
9497

9598
Console.WriteLine($"Found customers: {String.Join(", ", customers.Select(c => c.Customer.Id))}");
9699
}
@@ -196,7 +199,7 @@ private static async Task DoLeftJoinAsync(DemoDbContext ctx)
196199
Console.WriteLine($"Found customers: {String.Join(", ", customerOrder.Select(co => $"{{ CustomerId={co.Customer.Id}, OrderId={co.Order?.Id} }}"))}");
197200
}
198201

199-
private static async Task DoBulkInsertIntoRealTableAsync(DemoDbContext ctx)
202+
private static async Task DoBulkInsertAsync(DemoDbContext ctx)
200203
{
201204
var id = Guid.NewGuid();
202205
var customersToInsert = new Customer(id, $"First name of '{id}'", $"Last name of '{id}'");
@@ -207,7 +210,7 @@ private static async Task DoBulkInsertIntoRealTableAsync(DemoDbContext ctx)
207210
Console.WriteLine($"Inserted customers: {insertedCustomer.Id}");
208211
}
209212

210-
private static async Task DoBulkInsertSpecifiedColumnsIntoRealTableAsync(DemoDbContext ctx)
213+
private static async Task DoBulkInsertSpecificColumnsAsync(DemoDbContext ctx)
211214
{
212215
var customersToInsert = new Customer(Guid.NewGuid(), "First name", "Last name");
213216

@@ -280,7 +283,7 @@ private static async Task DoBulkInsertIntoTempTableAsync(DemoDbContext ctx, List
280283
Console.WriteLine($"Found order items: {String.Join(", ", orderItems.Select(i => $"{{ OrderId={i.OrderId}, ProductId={i.ProductId}, Count={i.Count} }}"))}");
281284
}
282285

283-
private static async Task DoBulkInsertEntitiesIntoTempTableAsync(DemoDbContext ctx)
286+
private static async Task DoBulkInsertIntoTempTableAsync(DemoDbContext ctx)
284287
{
285288
var id = Guid.NewGuid();
286289
var customersToInsert = new[]

samples/Thinktecture.EntityFrameworkCore.Sqlite.Samples/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public static async Task Main(string[] args)
2828
ctx.ChangeTracker.Clear(); // resetting DbContext, as an alternative to create a new one
2929

3030
// Bulk insert into temp tables
31-
await DoBulkInsertIntoTempTableAsync(ctx);
31+
await BulkInsertIntoTempTableAsync(ctx);
3232
ctx.ChangeTracker.Clear();
3333

3434
// Bulk insert into "real" tables
35-
await DoBulkInsertIntoRealTableAsync(ctx);
35+
await DoBulkInsertAsync(ctx);
3636
ctx.ChangeTracker.Clear();
3737

38-
await DoBulkInsertSpecifiedColumnsIntoRealTableAsync(ctx);
38+
await DoBulkInsertSpecificColumnsAsync(ctx);
3939
ctx.ChangeTracker.Clear();
4040

4141
// Bulk update
@@ -111,7 +111,7 @@ private static async Task DoLeftJoinAsync(DemoDbContext ctx)
111111
Console.WriteLine($"Found customers: {String.Join(", ", customerOrder.Select(co => $"{{ CustomerId={co.Customer.Id}, OrderId={co.Order?.Id} }}"))}");
112112
}
113113

114-
private static async Task DoBulkInsertIntoTempTableAsync(DemoDbContext ctx)
114+
private static async Task BulkInsertIntoTempTableAsync(DemoDbContext ctx)
115115
{
116116
var customersToInsert = new Customer(Guid.NewGuid(), "First name", "Last name");
117117
await using var tempTable = await ctx.BulkInsertIntoTempTableAsync(new[] { customersToInsert });
@@ -121,7 +121,7 @@ private static async Task DoBulkInsertIntoTempTableAsync(DemoDbContext ctx)
121121
Console.WriteLine($"Customer from temp table: {insertedCustomer.Id}");
122122
}
123123

124-
private static async Task DoBulkInsertIntoRealTableAsync(DemoDbContext ctx)
124+
private static async Task DoBulkInsertAsync(DemoDbContext ctx)
125125
{
126126
var customersToInsert = new Customer(Guid.NewGuid(), "First name", "Last name");
127127
await ctx.BulkInsertAsync(new[] { customersToInsert });
@@ -131,7 +131,7 @@ private static async Task DoBulkInsertIntoRealTableAsync(DemoDbContext ctx)
131131
Console.WriteLine($"Inserted customer: {insertedCustomer.Id}");
132132
}
133133

134-
private static async Task DoBulkInsertSpecifiedColumnsIntoRealTableAsync(DemoDbContext ctx)
134+
private static async Task DoBulkInsertSpecificColumnsAsync(DemoDbContext ctx)
135135
{
136136
var customersToInsert = new Customer(Guid.NewGuid(), "First name", "Last name");
137137

0 commit comments

Comments
 (0)