我正在使用 Dapper、Dapper.Extensions 和 Dapper.SimpleCRUD。以下代码在针对 MYSQL 数据库运行时可以正常工作。但是,当我对 oracle 使用相同的表运行相同的代码时,我得到 ORA-00936:缺少表达式错误。我不确定为什么会收到此错误,因为我只是想从表中检索所有记录。
//MYSQL DDL
CREATE TABLE app_config(
`app_config_id` int AUTO_INCREMENT NOT NULL,
`user_name` nvarchar(100) NULL,
`program_location` nvarchar(400) NULL,
CONSTRAINT PK_tk_app_config_id PRIMARY KEY (app_config_id) );
//ORACLE DDL
CREATE TABLE app_config(
app_config_id number(10) NOT NULL,
user_name nvarchar2(100) NULL,
program_location nvarchar2(400) NULL,
CONSTRAINT PK_tk_app_config_id PRIMARY KEY (app_config_id));
CREATE SEQUENCE app_config_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER app_config_seq_tr
BEFORE INSERT ON app_config FOR EACH ROW
WHEN (NEW.app_config_id IS NULL)
BEGIN
SELECT app_config_seq.NEXTVAL INTO :NEW.app_config_id FROM DUAL;
END;
/
//C# Code
using System;
using System.Linq;
using System.Data.SqlClient;
using Dapper;
namespace RetrieveAll
{
public class app_config
{
[Key]
public int app_config_id { get; set; }
public string user_name { get; set; }
public string program_location { get; set; }
}
public static IDbConnection getDBConnection(string dbtype)
{
switch (dbtype)
{
default:
case "MYSQL":
return new MySqlConnection("userid=uid;password=pwd;server=localhost;database=test");
case "ORACLE":
return new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=tempdb)));User ID=uid;Password=pwd;");
}
}
class Program
{
static void Main(string[] args)
{
using (var connection = dbConnector.getDBConnection("ORACLE"))
{
var ac = connection.GetList<app_config>().ToList();
}
}
}
}