本文介绍了LinqToSQL InsertOnSubmit和InsertAllOnSubmit之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对LINQ to SQL有疑问.
I have a question about LINQ to SQL.
什么更快?
public void CreateLocationImages(IEnumerable<LocationImage> list)
{
_db.LocationImages.InsertAllOnSubmit(list);
_db.SubmitChanges();
}
或
public void CreateLocationImages(IEnumerable<LocationImage> list)
{
foreach (LocationImage item in list)
{
_db.LocationImages.InsertOnSubmit(item);
}
_db.SubmitChanges();
}
还是没有区别?
推荐答案
由于在这两种情况下,您都仅一次呼叫SubmitChanges
.这两个代码将导致相同的性能. (如果性能上的差异应该忽略不计) 如果您的第二个代码段在for循环中包含_db.SubmitChanges();
,那么它将是一个单独的连接并在db中插入语句.
Since in both cases you are calling SubmitChanges
only once. Both of the code would result in same performance. (if there is going to be any performance different that should be negligible) If your 2nd code segment has _db.SubmitChanges();
inside the for loop then it would be a separate connection and insert statement in the db.
这篇关于LinqToSQL InsertOnSubmit和InsertAllOnSubmit之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!