After researching Dapper, I discovered that it does not support bulk insert, bulk update, or bulk delete. Therefore, I have written a library to support these operations.
Performance
The table below describes the performance in milliseconds of the methods corresponding to the respective database types with 500 records.
Method | SQL Server | MySQL | PosgreSQL | SQLite |
---|---|---|---|---|
Insert | 24900 | 8600 | 5300 | 7900 |
Bulk Insert | 111 | 88 | 53 | 89 |
Update | 9500 | 22600 | 4800 | 6500 |
Bulk Update | 889 | 112 | 96 | N/A |
Delete | 17200 | 23800 | 5400 | 6100 |
Bulk Delete | 194 | 150 | 1200 | 115 |
SQLite does not meet the bulk update requirement because it does not support any bulk update method.
Nuget
dotnet add package Bulk.Dapper
Example
for example User
public class User
{
[Key]
public int id { get; set; }
public string name { get; set; }
public int age { get; set; }
}
List<User> users = new List<User>
{
new User { name = "Joe", age = 10 },
new User { name = "Donal", age = 10 }
};
Insert
Normal
connection.BulkInsert(users);
Async
connection.BulkInsertAsync(users);
Update
Normal
connection.BulkUpdate(users);
Async
connection.BulkUpdateAsync(users);
Delete
connection.BulkDelete(users);
Async
connection.BulkDeleteAsync(users);
Set Table name and column name
Can change the table name by attribute Table, column name by attribute ColumnName
[Table("Users")]
public class UserChangeColumn
{
[Key]
public int id { get; set; }
[ColumnName("name")]
public string fullname { get; set; }
public int age { get; set; }
}
Note
Other attributes are the same as Dapper.Contrib
Top comments (0)