ASP.NET Core -找不到类型或命名空间名称“OracleDynamicParameters”

b5buobof  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(161)

在ASP.NETCore6与Dapper和Oracle数据库中,我有一个存储过程可以使用。
我有这些金块包裹

Dapper Version 2.0.123 
Oracle.ManagedDataAccess.Core Version 3.21.100

然而,我得到了这个错误:
错误CS0246
找不到类型或命名空间名称“OracleDynamicParameters”(是否缺少using指令或程序集引用?)
这是我的存储过程:

create or replace PROCEDURE  "GET_STUDENT_DETAILS" (
        sUserID     IN VARCHAR DEFAULT NULL,
        rResultSet  OUT SYS_REFCURSOR
        )
AS
nCheck        NUMBER;
sUserIDC      VARCHAR(100);

BEGIN
    select instr(sUserID,'.') into nCheck from dual;

IF nCheck>0 THEN 

    SELECT CONCAT(sUserID,'@rotrim.com') into sUserIDC FROM DUAL;
    
    OPEN rResultSet FOR   
    SELECT SU."USER_ID",
          SU."USER_NAME",
          SU."FIRST_NAME",
          SU."LAST_NAME",
        CFUF."EMAIL"
      FROM PEPUSC.smtb_user su, PEPUSC.cstm_function_userdef_fields cfuf
      WHERE su."USER_ID"||'~'=cfuf."REC_KEY"
      AND cfuf."FUNCTION_ID"= 'SMDUSRDF'
      AND  SU. USER_NAME = sUserIDC
      AND SU.USER_STATUS = 'E';
      
ELSE 

OPEN rResultSet FOR
    SELECT SU."USER_ID",
          SU."USER_NAME",
          SU."FIRST_NAME",
          SU."LAST_NAME",
        CFUF."EMAIL"
      FROM PEPUSC.smtb_user su, PEPUSC.cstm_function_userdef_fields cfuf
      WHERE su."USER_ID"||'~'=cfuf."REC_KEY"
      AND cfuf."FUNCTION_ID"= 'SMDUSRDF'
      AND SU.USER_ID = sUserID
      AND SU.USER_STATUS = 'E';
END IF;
END;

这是我的C#代码:

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using Dapper;

public class StudentRepository : IStudentRepository
{
    private readonly IMapper _mapper;
    private readonly IConfiguration _configuration;
    private readonly ILogger<StudentRepository> _logger;

    public StudentRepository(IMapper mapper,
        ILogger<StudentRepository> logger,
        IConfiguration configuration)
    {
        _mapper = mapper;
        _logger = logger;
        _configuration = configuration;
    }

    public IDbConnection Connection
    {
        get { return new OracleConnection(_configuration.GetConnectionString("DefaultConnection")); }
    }

    public async Task<Response<StudentResponseDto>> GetStudentByUserIdAsync(string sUserID)
    {
        var response = new Response<StudentResponseDto>();

        try
        {
            using (IDbConnection _dbConnection = Connection)
            {
                _dbConnection.Open();
                //
                var parameters = new OracleDynamicParameters();
                parameters.Add("sUserID", sUserID, OracleDbType.Varchar2, ParameterDirection.Input);
                parameters.Add("rResultSet", OracleDbType.RefCursor, ParameterDirection.Output);

                string query = "GET_STUDENT_DETAILS";

                var student = await _dbConnection.QueryFirstOrDefaultAsync<StudentResponse>(query, parameters, commandType: CommandType.StoredProcedure);

                if (fcubsHeader != null)
                {
                    var studentDtos = _mapper.Map<StudentResponseDto>(fcubsHeader);
                    response.Successful = true;
                    response.Data = studentDtos;
                    response.StatusCode = (int)HttpStatusCode.OK;
                    return response;
                }
                else
                {
                    response.Message = $"Data Not Found!";
                    response.Successful = true;
                    response.StatusCode = (int)HttpStatusCode.NoContent;
                    return response;
                }
            }
        }
        catch (OracleException ex)
        {
            response.Successful = false;
            response.StatusCode = (int)HttpStatusCode.BadRequest;
            return response;
            throw;
        }
        catch (Exception ex)
        {
            response.Successful = false;
            response.StatusCode = (int)HttpStatusCode.BadRequest;
            return response;
            throw;
        }
    }
}

我该如何解决问题?

jei2mxaa

jei2mxaa1#

看起来OracleDynamicParametersDapperOracle 的实现中都不存在。
然而,从一些研究来看,有一个开发人员实现了这个OracleDynamicParameters来用Dapper查询Oracle存储过程。你可能读过这篇文章:Call Oracle Store procedure with Dapper (C#)并实现它。
如果你正在寻找一个纯粹的Dapper解决方案,你需要迁移代码:
1.从OracleDynamicParameters迁移到DynamicParameters
1.从OracleDbType迁移到DbType
OracleDbType文档:
OracleDbType属性和DbType属性是链接的。因此,设置OracleDbType属性会将DbType属性更改为支持DbType
有关从OracleDbType切换到DbType的参考,请参阅从OracleDbType推断DbType。

using System.Data;
var parameters = new DynamicParameters();
parameters.Add("sUserID", sUserID, dbType: DbType.String, direction: ParameterDirection.Input);
parameters.Add("rResultSet", null, dbType: DbType.Object, direction: ParameterDirection.Output);

相关问题