문제

My scenario is little bit wierd, I have a list of entities, say i have ten items in list which will go to three different tables , associated to each other. I am using Linq 2 Sql and I need to insert it in a single hit instead of multiple iterations.

Is this possible. I have heard, in BLtoolkit there is InsertBatch() method that performs a bulk insert. Anything similar in L2S.

도움이 되었습니까?

해결책

In short: No, it is not possible.

InsertAllOnSubmit is basically just calling InsertOnSubmit each time. So that does not help a lot.

If you profile the generated SQL, you will see that you will get a lot of individual insert statements resulting in a lot of overhead. Regardless of using InsertOnSumbit or InsertAllOnSumbit.

If you google around, you will see some attempts to add SqlBulkCopy behaviour to Linq-2-sql. For example: http://blogs.microsoft.co.il/blogs/aviwortzel/archive/2008/05/06/implementing-sqlbulkcopy-in-linq-to-sql.aspx

However, I think you might be better of implementing SqlBulkCopy yourself for your batch jobs.

다른 팁

There is InsertAllOnSubmit. With Linq To SQL, you just set the properties you want to change for an update. Then calling SubmitChanges will do the rest for you..

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top