EntityFramework-Extensions
EntityFramework-Extensions copied to clipboard
DiagnosticListener.AllListeners
Description
We use multiple database with different schemas with EF Core 7.0 We have a global command listener that changes the schema name before it executes.
Program.cs DiagnosticListener.AllListeners.Subscribe(new GlobalListener());
public class GlobalListener : IObserver<DiagnosticListener>
public void OnNext(KeyValuePair<string, object> value)
{
// there no key that matches this value.Key
if (value.Key == RelationalEventId.CommandExecuting.Name)
{
// NEVER ENTERS THIS BLOCK
var command = ((CommandEventData)value.Value).Command;
command.CommandText = command.CommandText
.Replace("[X.Shared].", "[X].[Shared].")
.Replace("[X1.Common].", "[X1].[Common].")
.Replace("[X2.Primary]","[X2].[Primary]")
}
}
The EntityFramework-Extensions never executes this block of code and I get exceptions saying the tables do not exists. It is the only way we can do it with our database design.
Is there a workaround for this issue? I need the schema/table names changed before the statements execute.
Exception
table does not exist
Exception message:
Stack trace:
- EF version: [EF Core v7.0.13]
- EF Extensions version: [EFE Core v7.100.0.0]
- Database Server version: [SQL Server 2022]
- Database Provider version (NuGet): [Microsoft.Data.SqlClient v5.1.2]