无法将“ServiceStack.OrmLite.OrmLiteDataParameter”类型的对象强制转换为“Oracle.DataAccess.Client.OracleParameter”

时间:2016-05-19 08:40:47

标签: oracle servicestack ormlite-servicestack

我正在使用此代码

using (var db = OpenDbConnection())
            if (db != null)
                db.Run(dbCnx =>
                {
                    var trans = dbCnx.BeginTransaction();

                        dbCnx.UpdateOnly(new ProtectiveMarkingRequest
                        {
                            SecondApproverUserName = request.SecondApproverUserName,
                            Status = request.Status
                        },
                            onlyFields: p => new
                            {
                                p.SecondApproverUserName,
                                p.Status
                            },
                            @where: p => p.WorkItemCode == request.WorkItemCode);
                    } 

                    trans.Commit();
                });

更新到servicestack.ormlite.oracle 4.0.52(从4.0.38)后,我收到以下错误:

System.InvalidCastException未被用户代码处理   的HResult = -2147467262   Message =无法将“ServiceStack.OrmLite.OrmLiteDataParameter”类型的对象强制转换为“Oracle.DataAccess.Client.OracleParameter”。   来源= Oracle.DataAccess   堆栈跟踪:        at Oracle.DataAccess.Client.OracleParameterCollection.Add(Object obj)        at ServiceStack.OrmLite.DbDataParameterExtensions.AddParam(IOrmLiteDialectProvider dialectProvider,IDbCommand dbCmd,Object value,Type fieldType)        at ServiceStack.OrmLite.Oracle.OracleOrmLiteDialectProvider.PrepareUpdateRowStatement(IDbCommand dbCmd,Object objWithProperties,ICollection 1 updateFields) at ServiceStack.OrmLite.WriteExpressionCommandExtensions.UpdateOnlySql[T](IDbCommand dbCmd, T model, SqlExpression 1 onlyFields)        at ServiceStack.OrmLite.WriteExpressionCommandExtensions.UpdateOnly [T](IDbCommand dbCmd,T model,SqlExpression 1 onlyFields) at ServiceStack.OrmLite.OrmLiteWriteExpressionsApi.<>c__DisplayClass7 2.b__6(IDbCommand dbCmd)        在ServiceStack.OrmLite.OrmLiteExecFilter.Exec [T](IDbConnection dbConn,Func`2过滤器)        在SecurityRepository.cs中的ECMAPI.Repository.Security.SecurityRepository。&lt;&gt; c__DisplayClassfb.b__f9(IDbConnection dbCnx):第1970行

任何线索?

1 个答案:

答案 0 :(得分:1)

要使用Transaction Support in OrmLite,您应该使用OpenTransaction()Run()扩展方法也不会提供任何值,因此我会将您的示例重写为:

using (var db = OpenDbConnection())
using (var trans = db.OpenTransaction())
{
    db.UpdateOnly(new ProtectiveMarkingRequest
        {
            SecondApproverUserName = request.SecondApproverUserName,
            Status = request.Status
        },
        onlyFields: p => new {
            p.SecondApproverUserName,
            p.Status
        },
        @where: p => p.WorkItemCode == request.WorkItemCode);
    } 
    trans.Commit();
}