InsertOnSubmit()長い時間がかかるという同じ問題がありました。
ただし、DataTableHelperクラス (以下のリンクからダウンロード可能) を使用し、コードの 1 ~ 2 行を変更するだけで、代わりに一括挿入を簡単に使用できます。
一括挿入
例えば:
const int RECORDS_TO_INSERT = 5000;
List<Product> recordsToBeInserted = new List<Product>();
using (NorthwindDataContext dc = new NorthwindDataContext())
{
for (int n = 0; n < RECORDS_TO_INSERT; n++)
{
Product newProduct = new Product()
{
ProductName = "Product " + n.ToString(),
UnitPrice = 3999,
UnitsInStock = 2,
UnitsOnOrder = 0,
Discontinued = false
};
recordsToBeInserted.Add(newProduct);
}
// Insert this List<> of records into the [Products] table in our database, using a Bulk Insert
DataTableHelper.BulkCopyToDatabase(recordsToBeInserted, "Products", dc);
}
お役に立てれば。