Skip to content

Commit 364d267

Browse files
committed
Initial Async Support
1 parent cf69f56 commit 364d267

File tree

6 files changed

+27
-32
lines changed

6 files changed

+27
-32
lines changed

src/EntityFrameworkCore.SqlServer.SimpleBulks.Benchmarks/TempTableBenchmarks.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ public void IterationCleanup()
4545
[Benchmark]
4646
public void CreateTempTable()
4747
{
48-
_context.CreateTempTable(_customers, opt =>
49-
{
50-
opt.Timeout = 0;
51-
});
48+
_context.CreateTempTable(_customers,
49+
x => new
50+
{
51+
x.Id,
52+
x.FirstName,
53+
x.LastName,
54+
x.CurrentCountryIsoCode,
55+
x.Index
56+
},
57+
opt =>
58+
{
59+
opt.Timeout = 0;
60+
});
5261
}
5362
}

src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextAsyncExtensions/TempTableTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public async Task Non_Entity_Type_Single_Table_With_All_Columns()
183183

184184
// Act
185185
var tableName = await _context.CreateTempTableAsync(_customers,
186+
["IdNumber", "FirstName", "LastName", "CurrentCountryIsoCode"],
186187
options =>
187188
{
188189
options.LogTo = _output.WriteLine;
@@ -219,12 +220,14 @@ public async Task Non_Entity_Type_Multiple_Tables_With_All_Columns()
219220

220221
// Act
221222
var customerTableName = await _context.CreateTempTableAsync(_customers,
223+
["IdNumber", "FirstName", "LastName", "CurrentCountryIsoCode"],
222224
options =>
223225
{
224226
options.LogTo = _output.WriteLine;
225227
});
226228

227229
var contactTableName = await _context.CreateTempTableAsync(_contacts,
230+
["EmailAddress", "PhoneNumber", "CustomerIdNumber", "CountryIsoCode"],
228231
options =>
229232
{
230233
options.LogTo = _output.WriteLine;
@@ -306,12 +309,14 @@ public async Task Entity_Type_Multiple_Tables()
306309

307310
// Act
308311
var customerTableName = await _context.CreateTempTableAsync(customers,
312+
["Id", "FirstName", "LastName", "Index"],
309313
options =>
310314
{
311315
options.LogTo = _output.WriteLine;
312316
});
313317

314318
var contactTableName = await _context.CreateTempTableAsync(contacts,
319+
["CustomerId", "EmailAddress", "PhoneNumber", "Index"],
315320
options =>
316321
{
317322
options.LogTo = _output.WriteLine;
@@ -368,6 +373,7 @@ public async Task Entity_Type_Single_Table_With_Mappings()
368373

369374
// Act
370375
var tableName = await _context.CreateTempTableAsync(configurationEntries,
376+
["Id", "Key", "Value"],
371377
options =>
372378
{
373379
options.LogTo = _output.WriteLine;

src/EntityFrameworkCore.SqlServer.SimpleBulks.Tests/DbContextExtensions/TempTableTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public void Non_Entity_Type_Single_Table_With_All_Columns()
183183

184184
// Act
185185
var tableName = _context.CreateTempTable(_customers,
186+
["IdNumber", "FirstName", "LastName", "CurrentCountryIsoCode"],
186187
options =>
187188
{
188189
options.LogTo = _output.WriteLine;
@@ -219,12 +220,14 @@ public void Non_Entity_Type_Multiple_Tables_With_All_Columns()
219220

220221
// Act
221222
var customerTableName = _context.CreateTempTable(_customers,
223+
["IdNumber", "FirstName", "LastName", "CurrentCountryIsoCode"],
222224
options =>
223225
{
224226
options.LogTo = _output.WriteLine;
225227
});
226228

227229
var contactTableName = _context.CreateTempTable(_contacts,
230+
["EmailAddress", "PhoneNumber", "CustomerIdNumber", "CountryIsoCode"],
228231
options =>
229232
{
230233
options.LogTo = _output.WriteLine;
@@ -306,12 +309,14 @@ public void Entity_Type_Multiple_Tables()
306309

307310
// Act
308311
var customerTableName = _context.CreateTempTable(customers,
312+
["Id", "FirstName", "LastName", "Index"],
309313
options =>
310314
{
311315
options.LogTo = _output.WriteLine;
312316
});
313317

314318
var contactTableName = _context.CreateTempTable(contacts,
319+
["CustomerId", "EmailAddress", "PhoneNumber", "Index"],
315320
options =>
316321
{
317322
options.LogTo = _output.WriteLine;
@@ -368,6 +373,7 @@ public void Entity_Type_Single_Table_With_Mappings()
368373

369374
// Act
370375
var tableName = _context.CreateTempTable(configurationEntries,
376+
["Id", "Key", "Value"],
371377
options =>
372378
{
373379
options.LogTo = _output.WriteLine;
Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Reflection;
53

64
namespace EntityFrameworkCore.SqlServer.SimpleBulks.Extensions;
75

@@ -27,26 +25,4 @@ public static string ToSqlType(this Type type)
2725
var sqlType = _mappings.TryGetValue(type, out string value) ? value : "nvarchar(max)";
2826
return sqlType;
2927
}
30-
31-
public static string[] GetDbColumnNames(this Type type, params string[] ignoredColumns)
32-
{
33-
var names = type.GetProperties()
34-
.Where(x => IsSupportedType(x))
35-
.Where(x => ignoredColumns == null || !ignoredColumns.Contains(x.Name))
36-
.Select(x => x.Name);
37-
return names.ToArray();
38-
}
39-
40-
public static string[] GetUnSupportedPropertyNames(this Type type)
41-
{
42-
var names = type.GetProperties()
43-
.Where(x => !IsSupportedType(x))
44-
.Select(x => x.Name);
45-
return names.ToArray();
46-
}
47-
48-
private static bool IsSupportedType(PropertyInfo property)
49-
{
50-
return _mappings.ContainsKey(Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType) || property.PropertyType.IsValueType;
51-
}
5228
}

src/EntityFrameworkCore.SqlServer.SimpleBulks/TempTable/DbContextAsyncExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static Task<string> CreateTempTableAsync<T>(this DbContext dbContext, IEn
3535
.ExecuteAsync(cancellationToken);
3636
}
3737

38-
public static Task<string> CreateTempTableAsync<T>(this DbContext dbContext, IEnumerable<T> data, Action<TempTableOptions> configureOptions = null, CancellationToken cancellationToken = default)
38+
public static Task<string> CreateTempTableAsync<T>(this DbContext dbContext, IEnumerable<T> data, IEnumerable<string> columnNames, Action<TempTableOptions> configureOptions = null, CancellationToken cancellationToken = default)
3939
{
4040
var connection = dbContext.GetSqlConnection();
4141
var transaction = dbContext.GetCurrentSqlTransaction();
@@ -44,7 +44,6 @@ public static Task<string> CreateTempTableAsync<T>(this DbContext dbContext, IEn
4444

4545
IReadOnlyDictionary<string, string> columnNameMappings = null;
4646
IReadOnlyDictionary<string, string> columnTypeMappings = null;
47-
IEnumerable<string> columnNames = typeof(T).GetDbColumnNames();
4847

4948
if (isEntityType)
5049
{

src/EntityFrameworkCore.SqlServer.SimpleBulks/TempTable/DbContextExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static string CreateTempTable<T>(this DbContext dbContext, IEnumerable<T>
3333
.Execute();
3434
}
3535

36-
public static string CreateTempTable<T>(this DbContext dbContext, IEnumerable<T> data, Action<TempTableOptions> configureOptions = null)
36+
public static string CreateTempTable<T>(this DbContext dbContext, IEnumerable<T> data, IEnumerable<string> columnNames, Action<TempTableOptions> configureOptions = null)
3737
{
3838
var connection = dbContext.GetSqlConnection();
3939
var transaction = dbContext.GetCurrentSqlTransaction();
@@ -42,7 +42,6 @@ public static string CreateTempTable<T>(this DbContext dbContext, IEnumerable<T>
4242

4343
IReadOnlyDictionary<string, string> columnNameMappings = null;
4444
IReadOnlyDictionary<string, string> columnTypeMappings = null;
45-
IEnumerable<string> columnNames = typeof(T).GetDbColumnNames();
4645

4746
if (isEntityType)
4847
{

0 commit comments

Comments
 (0)