sql >> Database teknologi >  >> RDS >> Oracle

Udfør SQL Alter-kommandoer for hver session med Entity Framework 5, der taler med Oracle 11g

du kan bruge metoden Database.Connection.StateChange

    public AtomContext(string nameOrConnectionString)
        : base(nameOrConnectionString)
    {
        this.Database.Connection.StateChange += Connection_StateChange;
    }

    void Connection_StateChange(object sender, StateChangeEventArgs e)
    {
        if (e.OriginalState == ConnectionState.Open || e.CurrentState != ConnectionState.Open)
            return;

        IDbConnection connection = ((EntityConnection)((IObjectContextAdapter)this).ObjectContext.Connection).StoreConnection;
        using (IDbCommand command = connection.CreateCommand("ALTER SESSION SET NLS_LANGUAGE=TURKISH"))
            command.ExecuteNonQuery();

        using (IDbCommand command = connection.CreateCommand("ALTER SESSION SET NLS_COMP = LINGUISTIC"))
            command.ExecuteNonQuery();

        using (IDbCommand command = connection.CreateCommand("ALTER SESSION SET NLS_SORT=TURKISH_AI"))
            command.ExecuteNonQuery();
    }



  1. Vis en tabel i en hver løkke med databaseværdier

  2. Indeks bliver ikke anvendt på indekseret visning

  3. SQL join mod datointervaller?

  4. Hvordan henter man Oracle-referencemarkøren til tabelvariablen?