Speed up LINQ inserts

前端 未结 11 1610
自闭症患者
自闭症患者 2021-02-01 07:46

I have a CSV file and I have to insert it into a SQL Server database. Is there a way to speed up the LINQ inserts?

I\'ve created a simple Repository method to save a rec

11条回答
  •  北海茫月
    2021-02-01 08:08

    Do you really need to check if the record exist before inserting it into the DB. I thought it looked strange as the data comes from a csv file.

    P.S. I've tried to use SqlBulkCopy, but I need to do some transformations on Offer before inserting it into the db, and I think that defeats the purpose of SqlBulkCopy.

    I don't think it defeat the purpose at all, why would it? Just fill a simple dataset with all the data from the csv and do a SqlBulkCopy. I did a similar thing with a collection of 30000+ rows and the import time went from minutes to seconds

提交回复
热议问题