How to do multiple insert as well update by using dapper .net?

.net c# dapper orm sql-server

Question

How to do multiple insert (50000 record) as well update using dapper .net ?

  1. Is it possible to use SqlBulkCopy to achieve this? If yes then how?

  2. Is there any best way to implement multiple hierarchical insert or update using Dapper.net?

Technologies : C#, SQL Server 2012, Dapper.net

Expert Answer

  1. If you just want to insert: SqlBulkCopy should be fine; if you want an "upsert", I suggest table-valued-parameters (which dapper supports) and the merge t-sql operation
  2. Dapper just simplifies ado.net; if you think of a way to do it in ado.net, dapper can probably make it easier for you; however, it sounds like multiple TVPs might suffice

Popular Answer

If you are mean to OK and able to segregate insert and update entities separately then I would suggest to use Dapper.Contrib library provided by Dapper.Net guys themselves. It is available via nuget. It has worked very efficiently for my project.

Here is the link to their Github project page.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why