I am looking for an efficient way to perform inserts of multiple rows with some values from multiple tables!
Basically I'm parsing an XML and creating a list of custom objects which I then want to insert to my database. Some of the values of these rows are contained in the XML but others need to be retrieved from other tables.
Example:
Two tables:
Person:
PersonID (identity), Name (nvarchar), CountryID
Country (a lookup table including my id and the one I get from the XML)
CountryID (identity) , CountryXMLID, Name
I go through my list in C#, create a list of Teams(custom objects) and then I want to do this for an average of 1000 rows per minute:
INSERT INTO Person (Name, CountryID)
SELECT 'George', CountryID FROM Countries WHERE CountryXMLID = '1';
Person name and country feed id are included in the XML. I want to use the ID in the Person table rather than the one in the XML..
Could someone please advice me on an efficient manner to perform these inserts.
I have been thinking about creating a DataTable and then using SQLBulkCopy, using a stored procedure to run a loop through the datatable and perform the above statement for each one, and ORM like EntityFramework, Telerik Data Access, etc..