如題。
貌似ForEach(q=>{ await ?EFContext.SaveChangesAsync() })會(huì)報(bào)錯(cuò),使用了同一個(gè)上下文錯(cuò)誤,如果用的同一個(gè)上下文,
但是foreach(var q in list)
{
await ?EFContext.SaveChangesAsync() ;不會(huì)報(bào)錯(cuò)。
}
下面代碼又能幫助理解嗎?
static void Main(string[] args)
{
#region Action<T>委托示例
//需求:打印出整型集合list的元素
List<int> list = new List<int>() { 1, 2, 3, 4, 5 };
//將匿名方法分配給 Action<T> 委托實(shí)例
Action<int> concat1 = delegate(int i) { Console.WriteLine(i); };
list.ForEach(concat1);
//將 lambda 表達(dá)式分配給 Action<T> 委托實(shí)例
Action<int> concat2 = (i => Console.WriteLine(i));
list.ForEach(concat2);
Console.ReadKey();
#endregion
}
- 1 回答
- 0 關(guān)注
- 655 瀏覽
添加回答
舉報(bào)
0/150
提交
取消