我有一个名为thing的函数(在循环中多次调用)调用InsertOnSubmit函数,在列表中添加要插入的实体。列表的元素的属性A和B已修改。在对SubmitCounter进行了一百次调用之后,提交了更改。
static int counter = 0;
static void Things()
{
List<TABLE> entityList = new List<TABLE>;
entityList = EntityLoad();
dbContext.InsertOnSubmit(entity);
SubmitCounter();
entityList.Add(entity)
foreach(TABLE entity in entityList)
{
[...]
entity.PROPERTYA = aVariable;
entity.PROPERTYB = anotherVariable;
SubmitCounter();
}
}
static void SubmitCounter()
{
counter++;
if(counter >= 100)
{
dbContext.SubmitChanges();
counter = 0;
}
}
您知道这些说明是否按照他们提交的顺序执行&#34;在程序执行中还是我们先插入插件,例如?
最终,要弄清楚上面代码的结果(以下代码的优化尝试)是否与以下代码的结果不同:
static int counter = 0;
static void Things()
{
List<TABLE> entityList = new List<TABLE>;
entityList = EntityLoad();
dbContext.InsertOnSubmit(entity);
dbContext.SubmitChanges();
entityList.Add(entity)
foreach(TABLE entity in entityList)
{
[...]
entity.PROPERTYA = aVariable;
entity.PROPERTYB = anotherVariable;
dbContext.SubmitChanges();
}
}
谢谢!