Skip to content
Advertisement

How to combine multiple INSERT INTO’s with prepared statements?

Using Dapper, is there a way to form this into one query with the prepared statements? The length of userIds is dynamic.

Advertisement

Answer

One of the many advantages of Dapper over straight ADO.NET is the simplicity of inserting a list of data to a table.
You just need a list of a class <T> where the properties of the class have the same name of your database fields, so…

You can use this approach if you want to maintain the actual interface of your current method, but, of course, nothing prevents you to build the list directly where you build the array and pass the list instead of the two parameters or even create an overload of this method that accepts the list as its input.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement