using System.Collections.Generic;
using System.Linq;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.Persistence
{
///
/// A provider that just generates insert commands
///
public class BasicBulkSqlInsertProvider : IBulkSqlInsertProvider
{
public string ProviderName => Cms.Core.Constants.DatabaseProviders.SqlServer;
public int BulkInsertRecords(IUmbracoDatabase database, IEnumerable records)
{
if (!records.Any()) return 0;
return BulkInsertRecordsWithCommands(database, records.ToArray());
}
///
/// Bulk-insert records using commands.
///
/// The type of the records.
/// The database.
/// The records.
/// The number of records that were inserted.
internal static int BulkInsertRecordsWithCommands(IUmbracoDatabase database, T[] records)
{
foreach (var command in database.GenerateBulkInsertCommands(records))
command.ExecuteNonQuery();
return records.Length; // what else?
}
}
}