在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;
}
}
}
我该如何解决问题?
1条答案
按热度按时间jei2mxaa1#
看起来
OracleDynamicParameters
在 Dapper 或 Oracle 的实现中都不存在。然而,从一些研究来看,有一个开发人员实现了这个
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。