質問

I have .NET application with Oracle Database and NHibernate. I need to handle some "Connected" event which raised before NHibernate executed first DbCommand with currently used OracleConnection. This is due to the necessity of primary context initialization. I need to be sure that before executing any command context was initialized. Is there such a possibility in NHibernate?

P.S. I can not use Oracle ON LOGON TRIGGER for this purpose

UPD. The solution is:

public class CustomConnectionProvider : DriverConnectionProvider
    {
        public override System.Data.IDbConnection GetConnection()
        {
            var conn = (OracleConnection)base.GetConnection();
            //init context
            return conn;
        }
    }
役に立ちましたか?

解決

You can use a custom DriverConnectionProvider. Normally this is used to dynamically change the connection but it seems like a good fit for your scenario. Since it's responsible for creating and opening the connection, you are guaranteed that no operations have occurred before it executes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top