How can I save a List in a database at once without iterating through the whole list and saving each object seperately to the database.
//So not like this solution
foreach(T t in data){
//Call function to save with stored procedure
Database.Save(t);
}
(Also without using the entity framework) (I only seem to get solutions based on the entity framework or Dapper.Net on StackOverflow.)
Is this even possible by sending the list in some way to the database and using a stored procedure?
@Edit Additional information
I'm currently running on SQL 2012 and want to be able to reroll everything if something did not work!
If you are using at least SQL Server 2008, then you can use a Table Valued parameter to do this. This question and answers covers the topic.
Essentially you create a Type in SQL, and then something in C# to convert you data to a IEnumerable<SqlDataRecord>
which matches the type as given.
You can use Table Valued Parameter
to pass collection to stored procedure.
MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With