sql >> Database >  >> RDS >> Oracle

EF-query naar Oracle die ORA-12704 gooit:tekenset komt niet overeen

Uiteindelijk kreeg ik de auteur hiervan (ODP.Net Managed Driver - ORA-12704:karakterset komt niet overeen in gegenereerde code) om de vraag bij te werken, hij plaatste een tijdelijke oplossing met behulp van een interceptor, ik zal hier wat meer in detail treden.. .

Eerst heb ik mijn DBContext ingericht om een ​​configuratie te laden. je kunt dit overslaan en gewoon toevoegen aan je configuratie als je die hebt:

[DbConfigurationType(typeof(MyDbConfiguration))]
public partial class MyContext : DbContext

Maak de configuratieklasse:

public class MyDbConfiguration : DbConfiguration
{
    public MyDbConfiguration()
    {
        this.AddInterceptor(new NVarcharInterceptor()); //add this line to existing config.
    }
}

Maak vervolgens de interceptor:

public class NVarcharInterceptor : IDbCommandInterceptor
{
    public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
    {
        if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
            command.CommandText = command.CommandText.Replace("N''", "''");
    }

    public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
    {
        if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
            command.CommandText = command.CommandText.Replace("N''", "''");
    }

    public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
    {
        if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
            command.CommandText = command.CommandText.Replace("N''", "''");
    }

    public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
    {
        if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
            command.CommandText = command.CommandText.Replace("N''", "''");
    }

    public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
    {
        if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
            command.CommandText = command.CommandText.Replace("N''", "''");
    }

    public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
    {
        if (command != null && !string.IsNullOrWhiteSpace(command.CommandText))
            command.CommandText = command.CommandText.Replace("N''", "''");
    }
}


  1. SQL Server:Dynamische waar-clausule

  2. Fix Error:"SELECT's links en rechts van UNION hebben niet hetzelfde aantal resultaatkolommen" in SQLite

  3. Converteer een Juliaanse dag naar een datum in PostgreSQL

  4. postgresql:INSERT INTO ... (SELECT * ...)