
In .NET, there is a very fast and easy way to pump a variety of entities into an SQL database: SqlBulkCopy
1public void BulkInsert<TEntity>(string connectionString, string tableName, IList<TEntity> entities, params string[] columns)
2{
3 using SqlBulkCopy sqlCopy = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.KeepNulls)
4 using ObjectReader reader = ObjectReader.Create(entities, columns);
5 {
6 sqlCopy.DestinationTableName = tableName;
7 sqlCopy.WriteToServer(reader);
8 }
9}
Usage:
1public class MyEntity
2{
3 public Id {get;set}
4 public Name {get;set;}
5 public EMail {get;set;}
6}
7
8public class MySqlExporter
9{
10 public void Export()
11 {
12 string connectionString = "your sql connection string";
13 string sqlTableName = "MyEntitiesTable";
14 List<MyEntity> myEntities = ... // here your code to read your existing entities or source
15
16 string[] copyParameters = {
17 nameof(MyEntity.Id)
18 nameof(MyEntity.Name),
19 nameof(MyEntity.EMail),
20 }
21
22 BulkInsert(connectionString, sqlTableName, myEntities, copyParameters);
23 }
24}
Related articles

Mar 10, 2026 · 15 min read
.NET NuGet Trusted Publishing with GitHub Actions
Publishing NuGet packages has traditionally required one uncomfortable compromise: a long-lived API key had to exist somewhere in the …

Mar 09, 2026 · 7 min read
C# 15 Unions: Unions are finally in .NET
After many years of workarounds, design discussions and library-level substitutes, unions are finally becoming a first-class part of C#. The …

Mar 02, 2026 · 19 min read
Unio: High-Performance Discriminated Unions for C#
C# is a powerful language, but there is one road it has not yet fully paved: native discriminated union types. Developers have been working …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

Comments