Insert Bulk Entries in SQL Server

Can someone tell me how to massage data in SQL Server in a transaction? I have a program to import data from several database tables from a file. I am using SQL Server and Entity Framework to import these records into a transaction database. Please tell me is this a good way to follow?

I am using Entity Framework for this. But when I import 1000 records, I find that it causes locks on SQL Server.

The file contains many columns. Several columns refer to the parent table, and the remaining columns refer to child tables. So how can we match them using SqlBulkCopy?

There are 10 child tables. I need to first insert data from a file into child tables. If inserting records causes an error in the child table, for what reason will I have to roll back this transaction and continue with another record from the file

+4
source share
2 answers

Today I found a good library for mass insertion: EntityFrameworkETL

PM> Install-Package EntityFrameworkETL

Project Description Entity Framework ETL is used for batch commands using an existing DbContext. This is useful when moving data between production and development.

Usage example

ETL = new EntityFrameworkETL.ETL(() => new DataContext("name=source"), () => new DataContext("name=target"));
ETL.DeleteAll<Person>();
ETL.BatchInserts<Person>(100, true, x => x.Include("Jobs").Where(y=> y.Age > 65 && y.IsRetired));
+2
source

. SQL.

, .

, .

0

Source: https://habr.com/ru/post/1523662/


All Articles