4

すべてのデータベース セッションの開始時にいくつかの SQL コマンドを実行する必要があります。Oracle 11g データベースと通信する DbContext 経由で Entity Framework 5 を使用しています。

実行したい:

ALTER SESSION SET NLS_COMP=ANSI;
ALTER SESSION SET NLS_SORT=BINARY_CI;

大文字と小文字を区別しない検索を取得するためのセッション作成の開始時。
これについてどのように最善を尽くすことができますか?

コマンドを dbContext のコンストラクターに入れましたが、単純な単体テストしかなく、機能しているように見えます。しかし、これが正しいことかどうかは不明です

public partial class Entities : DbContext
{
    public Entities()
        : base("name=Entities")
    {
        this.Database.ExecuteSqlCommand("ALTER SESSION SET NLS_COMP=ANSI");
        this.Database.ExecuteSqlCommand("ALTER SESSION SET NLS_SORT=BINARY_CI");
    }
}
4

3 に答える 3

2

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();
    }

于 2016-05-15T00:46:26.673 に答える
0

もう 1 つのオプションは、「LOGON TRIGGER ON SCHEMA」です。しかし、DBA に作成を強制するかどうかは疑問です。ログオン トリガーは「危険」と見なされます。

于 2013-01-17T18:16:03.137 に答える