Dapper.Bulk
Dapper.Bulk SqlServer
Dapper.Bulk- bulk inserts for Dapper =========================================== The project is written primarily in C#, distributed under the MIT License license, first published in 2017. Key topics include: bulk, dapper, fast-insert, insert, inserts-entities.
Latest release: v1.6.0— Dapper.Bulk v1.6.0
February 8, 2023View Changelog →
Dapper.Bulk- bulk inserts for Dapper
Features
Dapper.Bulk contains helper methods for bulk inserting.
Download
<a href="https://www.nuget.org/packages/Dapper.Bulk/" target="_blank">Dapper.Bulk Nuget</a>
PM> Install-Package Dapper.Bulk
Usage
- Inserts entities, without result for best performance:
csharpconnection.BulkInsert(data);
csharpawait connection.BulkInsertAsync(data);
- Inserts and returns inserted entities:
csharpvar inserted = connection.BulkInsertAndSelect(data);
csharpvar inserted = await connection.BulkInsertAndSelectAsync(data);
Default Conventions
TableNameis TypeName + s. When InterfaceIis removed.Keyis Id property (case-insensitive)
Custom Conventions
TableName - somewhere before usage call.
csharpTableMapper.SetupConvention("tbl", "s")
Attributes
We do not rely on specific attributes. This means you can use whatever attributes with following names:
TableAttribute- Must have string Name property. Exists in System.ComponentModel.Annotations Nuget.ColumnAttribute- Must have string Name property. Exists in System.ComponentModel.Annotations Nuget.KeyAttribute- Marking only attribute. Exists in System.ComponentModel.Annotations Nuget.ComputedAttribute- Marking only attribute. For fields returned from Db.NotMapped- Marking only attribute. For ignored fields.
csharp// Table Cars by default convention public class Car { // Identity by convention public int Id { get; set; } public string Name { get; set; } public DateTime ManufactureDate { get; set; } }
csharp// Supported in v1.2+ public enum CarType : int { Classic = 1, Coupe = 2 } [Table("tblCars")] public class Car { [Key] // Identity public int CarId { get; set; } public string Name { get; set; } public CarType CarType { get; set; } //SQL Data Type should match Enum type [Computed] // Will be ignored for inserts, but the value in database after insert will be returned public DateTime ManufactureDate { get; set; } }
csharppublic class IdentityAndNotMappedTest { [Key] public int IdKey { get; set; } public string Name { get; set; } // Will be ignored for inserts public virtual TestSublass TestSublass { get; set; } [NotMapped] // Will be ignored for inserts public int Ignored { get; set; } }
csharp// Supported in v1.4+ private class CustomColumnName { [Key] public int IdKey { get; set; } [Column("Name_1")] // Will map to SQL column Name_1 public string Name { get; set; } [Column("Int_Col")] // Will map to SQL column Int_Col public int IntCol { get; set; } [Column("Long_Col")] // Will map to SQL column Long_Col public long LongCol { get; set; } [NotMapped] // Will be ignored for inserts public int Ignored { get; set; } [Write(false)] // Will be ignored for inserts public int Ignored { get; set; } }
Contributors
Showing top 7 contributors by commit count.
This article is auto-generated from KostovMartin/Dapper.Bulk via the GitHub API.Last fetched: 6/16/2026
