Dapper和Oracle CRUD问题,怎么办? [英] Dapper and Oracle CRUD issues, how to?

查看:53
本文介绍了Dapper和Oracle CRUD问题,怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使Dapper.NET欺骗我的Oracle数据库?

How do i make Dapper.NET to CRUD my Oracle DB?

我的表名为: PLAYER_LOG 它的身份由触发器完成,这是sql

I have table named: PLAYER_LOG it's identity is done by trigger, here is the sql

SELECT SQ_MASTER_SEQUENCE.NEXTVAL INTO tmpVar FROM dual;
:NEW.ID := tmpVar;

我的模型是:

public class PlayerLogStorage : IEntity //-> here is the identity
{       
    public string Cli { get; set; }
    public string PlayerAnswer { get; set; }
    public DateTime InsertDate { get; set; }
}

这是我的插入内容:

 using (IDbConnection ctx = DbConnectionProvider.Instance.Connection)
 {
            ctx.Query<PlayerLogStorage>("INSERT INTO PLAYER_LOG (CLI, ANSWER, INSERT_DATE) VALUES (:Cli, :PlayerAnswer, :InsertDate)", new
            {
                Cli = model.Cli,
                PlayerAnswer = model.PlayerAnswer,
                InsertDate = model.InsertDate
            });
 }

这里是例外:

ORA-01008: not all variables bound


推荐答案

我遇到了一些类似的问题,但是使用了返回语句。我发现的技巧是使用DynamicParameters对象。在我使用的系统中,插入语句必须在序列上调用NextVal,它不在触发器中。

I have ran into something a little similar, but using the returning statement. The trick I found was to use the DynamicParameters object. In the system I use, the insert statements have to invoke NextVal on the sequence, it is not in a trigger.

var param = new DynamicParameters();

param.Add(name: "Cli", value: model.Cli, direction: ParameterDirection.Input);
param.Add(name: "PlayerAnswer", value: model.PlayerAnswer, direction: ParameterDirection.Input);
param.Add(name: "InsertDate", value: model.InsertDate, direction: ParameterDirection.Input);
param.Add(name: "Id", dbType: DbType.Int32, direction: ParameterDirection.Output);

using (IDbConnection ctx = DbConnectionProvider.Instance.Connection)
{
    ctx.Execute("INSERT INTO PLAYER_LOG (CLI, ANSWER, INSERT_DATE) VALUES (:Cli, :PlayerAnswer, :InsertDate) returning Id into :Id", paramList);
}

var Id = param.get<int>("Id");

这篇关于Dapper和Oracle CRUD问题,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆