Use LINQ to insert data from dataset to SQL

Posted by Mayo on Stack Overflow See other posts from Stack Overflow or by Mayo
Published on 2010-04-16T21:44:41Z Indexed on 2010/04/16 22:43 UTC
Read the original article Hit count: 177

Filed under:
|
|

Let's say I have a dataset in an ASP.NET website (.NET 3.5) with 5 tables, each has roughly 30,000 rows and an average of 12 columns. I want to insert all of the data from the dataset into 5 very-similar-but-not-quite-identical tables in SQL Server 2008. I also want to use LINQ (personal preference - trying to learn something new).

Is it as simple as iterating through the dataset and, for each row, creating a new instance of the associated class, initializing its data with the dataset's row, adding it to the data model, and then doing one giant SubmitChanges at the end?

Are there better ways of doing this with LINQ? Or is this the de-facto standard?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about sql