I have a C# console app that needs to insert/update records. At this time, these records are represented by a C# object that looks like this:
public class Record
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Count { get; set; }
public void Save()
{
}
}
In my C# code, I have a loop that goes through a List<Record>
. This loop updates the Count
if a Record
with a specific Id
exists. If a Record
with the specific Id
does not exist, I want to add a new Record
. I might have hundreds of Record
objects that need to get saved to the database.
Currently, my app is using the System.Data.SqlClient. I know how to insert / update records one-at-a-time. However, since I'm saving hundreds of Record
objects, this approach is slow. I'd like to batch them together and run the SQL once to speed things up.
How do I do that from C# with System.Data.SqlClient
?