Beispiel #1
0
        public virtual DbActionResult <IList> Query(string sql, DBParameterCollection dbParameters, Type dataType, DbActionOptions options = null)
        {
            var queryParameter = new QueryParameter(sql, dbParameters, options, dataType);

            return(ActionWithConnectionHandler(() =>
            {
                Log("QueryList", sql, dbParameters);
                var dynamicParameter = CreateDynamicParameters(dbParameters);
                IList list = _connection.Query(dataType, sql, dynamicParameter, _transaction).ToList();
                if (dataType != null)
                {
                    list = AncestorResultHelper.MakeList(list, dataType);
                }
                return list;
            }, queryParameter));
        }
Beispiel #2
0
        protected override void RestoreParameter(IDbDataParameter dbDataParameter, DBParameter dbParameter)
        {
            var oracleParameter = dbDataParameter as OracleParameter;

            if (oracleParameter != null)
            {
                switch (oracleParameter.OracleDbType)
                {
                case OracleDbType.Varchar2:
                    oracleParameter.Value = GetString(oracleParameter.Value);
                    break;

                case OracleDbType.Int16:
                case OracleDbType.Int32:
                case OracleDbType.Int64:
                case OracleDbType.Single:
                case OracleDbType.Double:
                case OracleDbType.Decimal:
                    oracleParameter.Value = GetDecimal(oracleParameter.Value, oracleParameter.OracleDbType);
                    break;

                case OracleDbType.Clob:
                    oracleParameter.Value = GetClob(oracleParameter.Value);
                    break;

                case OracleDbType.RefCursor:
                    var table = GetRefCursor(oracleParameter.Value);
                    if (dbParameter.ItemType != null)     // convert to list
                    {
                        var enumerator = AncestorResultHelper.TableToCollection(table, dbParameter.ItemType, null, false, ResultListMode.All, dbParameter.ItemEncoding);
                        var list       = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(dbParameter.ItemType));
                        var e          = enumerator.GetEnumerator();
                        while (e.MoveNext())
                        {
                            list.Add(e.Current);
                        }
                        oracleParameter.Value = list;
                    }
                    else
                    {
                        oracleParameter.Value = table;
                    }
                    break;
                }
            }
            base.RestoreParameter(oracleParameter, dbParameter);
        }