Skip to content

Latest commit

History

95 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Dapper.Bulk- bulk inserts for Dapper

Features

Dapper.Bulk contains helper methods for bulk inserting.

Download

Dapper.Bulk Nuget

PM> Install-Package Dapper.Bulk

Usage

  • Inserts entities, without result for best performance:
connection.BulkInsert(data);
awaitconnection.BulkInsertAsync(data);
  • Inserts and returns inserted entities:
varinserted=connection.BulkInsertAndSelect(data);
varinserted=awaitconnection.BulkInsertAndSelectAsync(data);

Default Conventions

  • TableName is TypeName + s. When Interface I is removed.
  • Key is Id property (case-insensitive)

Custom Conventions

TableName - somewhere before usage call.

TableMapper.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.
// Table Cars by default convention publicclassCar{// Identity by conventionpublicintId{get;set;}publicstringName{get;set;}publicDateTimeManufactureDate{get;set;}}
// Supported in v1.2+publicenumCarType:int{Classic=1,Coupe=2}[Table("tblCars")]publicclassCar{[Key]// IdentitypublicintCarId{get;set;}publicstringName{get;set;}publicCarTypeCarType{get;set;}//SQL Data Type should match Enum type[Computed]// Will be ignored for inserts, but the value in database after insert will be returnedpublicDateTimeManufactureDate{get;set;}}
publicclassIdentityAndNotMappedTest{[Key]publicintIdKey{get;set;}publicstringName{get;set;}// Will be ignored for insertspublicvirtualTestSublassTestSublass{get;set;}[NotMapped]// Will be ignored for insertspublicintIgnored{get;set;}}
// Supported in v1.4+privateclassCustomColumnName{[Key]publicintIdKey{get;set;}[Column("Name_1")]// Will map to SQL column Name_1publicstringName{get;set;}[Column("Int_Col")]// Will map to SQL column Int_ColpublicintIntCol{get;set;}[Column("Long_Col")]// Will map to SQL column Long_ColpubliclongLongCol{get;set;}[NotMapped]// Will be ignored for insertspublicintIgnored{get;set;}[Write(false)]// Will be ignored for insertspublicintIgnored{get;set;}}

About

Dapper.Bulk SqlServer

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages