1

以下代码的最后一行触发了异常:OracleConnection conn = new OracleConnection(getConnectionString());

        // A SqlConnection, SqliteConnection ... or whatever          
        // wrap the connection with a profiling connection that tracks timings      
        var cnn = MvcMiniProfiler.Data.ProfiledDbConnection.Get(conn, MiniProfiler.Current); 
        OracleCommand cmd = new OracleCommand(sql, (OracleConnection) cnn);

这是:

Unable to cast object of type 'MvcMiniProfiler.Data.ProfiledDbConnection' to type 'Oracle.DataAccess.Client.OracleConnection'.

我正在使用 Oracle 数据提供程序。用于 oracle 的 devArt 也是如此。

谢谢 :)

4

1 回答 1

2

那是因为您需要将其视为抽象连接,并使用基类/接口上现有的CreateCommand, CreateParameteretc 方法。或者,如果您想避免这种混淆 - “dapper”(或任何其他 ADO.NET 实用程序层)之类的东西会为您省去很多麻烦。

这里的原因是分析器“装饰”连接,这反过来意味着它必须装饰其他对象并在正确的时间展开它们。这确实是如何以这种方式分析 ADO.NET

于 2011-07-29T19:17:35.843 回答