I have a library that is doing bulk insert.
Library is EfCore extension made in .NetStandard(1.4) so it can be used in ASP.NET Core projects targeting both .NetCore(1.0+) or full NetFramework(4.6.1+)
One of the functions is:
public static BulkInsert<T>(this DbContext context, IList<T> entities)
{
SqlBulkOperation.InsertAsync<T>(context, entities);
}
internal static class SqlBulkOperation
{
public static void Insert<T>(DbContext context, IList<T> entities)
{
....
sqlBulkCopy.WriteToServer(reader);
....
}
}
Next I have added the same method with async support
public static async Task BulkInsertAsync<T>(this DbContext context, IList<T> entities)
{
await SqlBulkOperation.InsertAsync<T>(context, entities, null, null);
}
internal static class SqlBulkOperation
{
public static async Task InsertAsync<T>(DbContext context, IList<T> entities)
{
....
await sqlBulkCopy.WriteToServer(reader);
....
}
}
And now I was advised to change the async method in a way to add ConfigureAwait(false) to internal method and also to optimize out simple async by removing explicit async keyword from exposed method like this:
public static Task BulkInsertAsync<T>(this DbContext context, IList<T> entities)
{
return SqlBulkOperation.InsertAsync<T>(context, entities, null, null, true);
}
internal static class SqlBulkOperation
{
public static async Task InsertAsync<T>(DbContext context, IList<T> entities)
{
await sqlBulkCopy.WriteToServerAsync(reader).ConfigureAwait(false);
}
}
So the question being:
In this situation is it better to use ConfigureAwait(false)?
And secondly is removing async keyword from exposed methods for scenario in example advisable?
PS I have already read few blogs and several questions here regarding these issue but still haven't come to conclusive answer. I read that ASP.NET Core no longer has a "context" so taking that into the consideration what would be the best practice here?