ASP.NET Core 6 MVC 應用程式使用 EF Core 和 Npgsql。
Ef 核心命令如
await ctx.Kasutajas.Where((k) => k.Kasutaja1 == suurusername).SingleOrDefaultAsync();
在缺少列的情況下拋出 PostgresException。BatchCommand 屬性為 null。看起來 EF Core 不使用批處理命令介面。在這種情況下如何獲取錯誤sql?
app.Use(async (context, next) =>
{
try
{
await next.Invoke();
}
catch (PostgresException ex)
{
ex.BatchCommand in null.
ex.InternalQuery is null.
Debug.WriteLine(ex.InternalQuery);
?? How to get error Sql ?
}
}
});
在 .NET 5 中,Ngpsql 對此有陳述句屬性,但根據
https://www.npgsql.org/doc/release-notes/6.0.html#npgsqlstatement-and-postgresexceptionstatement-have-been-removed
如何在例外處理程式的 CATCH 塊中獲取錯誤 SQL?https://github.com/npgsql/npgsql/issues/4222 中的討論沒有提供解決方案。
uj5u.com熱心網友回復:
正在為常規命令添加 PostgresException.BatchCommand 支持,例如 6.0 之前的 Npgsql 中的 PostgresException.Statement。請參閱https://github.com/npgsql/npgsql/issues/4222。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/385353.html
