環境為:
dotnet core 3.1 webapi efcore
maridb 10
Pomelo.EntityFrameworkCore.MySql
解決方案:
await _context.SaveChangesAsync();
異步操作要加await,不然會出現此異常。
參考:https://github.com/mysql-net/MySqlConnector/issues/496
It is not permitted to have multiple in-flight async operations on the same connection at the same time; you do have to await any existing operation before starting a new one.
However, you should also get a more helpful exception message (better than Packet received out-of-order) that helps you understand the problem and fix it. So if you are able to get a repro or a code sample that shows the problem, that would be good as it could help me identify where there is a missing check (for this invalid behaviour) in the code.
不允許同時在同一連接上進行多個進行中異步操作;您必須await任何現有的異步操作然后再開始一個新的操作。
但是,您還應該獲得一條更有用的異常消息(比Packet received out-of-order這有助於你理解並解決問題。因此,如果您能夠獲得顯示問題的repro或代碼示例,那將是很好的,因為它可以幫助我識別代碼中缺少檢查(這種無效行為)的位置。