Dapper Plus Chaining Action

Action

All Bulk Operations start with one of the following actions:

You can include lists directly in the method or you can chain your action with Also[Action] and Then[Action] methods.

connection.BulkInsert(invoices, x => x.InvoiceMeta, x => x.InvoiceItems, x=> x.InvoiceItems.Select(y => y.InvoiceItemMeta));

Try it

Also Action

When you chain your action with the Also[Action] method, you stay at the same level.

For example, if you BulkInsert an invoice, and use AlsoBulkInsert on your InvoiceItems, the level is still the Invoice.

So, the next Bulk Operations will be related to the Invoice, in this example, the InvoiceMeta.

connection.BulkInsert(invoices)
		  .AlsoBulkInsert(invoice => invoice.InvoiceMeta)
		  .AlsoBulkInsert(invoice => invoice.InvoiceItems, invoiceItem => invoiceItem.InvoiceMeta);

Try it

Method:

Then Action

When you chain your action with the Then[Action] method, you move to the next level

For example, if you BulkInsert an invoice, and use ThenBulkInsert on your InvoiceItems, the level is now the InvoiceItems.

So, the next Bulk Operations will be related to the InvoiceItem, in this example, the InvoiceItemMeta.

connection.BulkInsert(invoices)
		  .AlsoBulkInsert(invoice => invoice.InvoiceMeta)
		  .ThenBulkInsert(invoice => invoice.InvoiceItems)
		  .ThenBulkInsert(invoiceItem => invoiceItem.InvoiceItemMeta);

Try it

Method:


Last updated: 2023-02-26
Author:


Contents