You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.4 KiB
69 lines
2.4 KiB
using Microsoft.EntityFrameworkCore;
|
|
using Oracle.ManagedDataAccess.Client;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using Znyc.Recruitment.Admin.Commons.IDbContext;
|
|
|
|
namespace Znyc.Recruitment.Admin.Commons.DbContextCore
|
|
{
|
|
/// <summary>
|
|
/// Oracle上下文
|
|
/// </summary>
|
|
public class OracleDbContext : BaseDbContext, IOracleDbContext
|
|
{
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="sql"></param>
|
|
/// <param name="cmdTimeout"></param>
|
|
/// <param name="parameters"></param>
|
|
/// <returns></returns>
|
|
public override DataTable GetDataTable(string sql, int cmdTimeout = 30, params DbParameter[] parameters)
|
|
{
|
|
return GetDataTables(sql, cmdTimeout, parameters).FirstOrDefault();
|
|
}
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="sql"></param>
|
|
/// <param name="cmdTimeout"></param>
|
|
/// <param name="parameters"></param>
|
|
/// <returns></returns>
|
|
public override List<DataTable> GetDataTables(string sql, int cmdTimeout = 30, params DbParameter[] parameters)
|
|
{
|
|
List<DataTable> dts = new List<DataTable>();
|
|
//TODO: connection 不能dispose 或者 用using,否则下次获取connection会报错提示“the connectionstring property has not been initialized。”
|
|
DbConnection connection = Database.GetDbConnection();
|
|
if (connection.State != ConnectionState.Open)
|
|
{
|
|
connection.Open();
|
|
}
|
|
|
|
using (OracleCommand cmd = new OracleCommand(sql, (OracleConnection)connection))
|
|
{
|
|
cmd.CommandTimeout = cmdTimeout;
|
|
if (parameters != null && parameters.Length > 0)
|
|
{
|
|
cmd.Parameters.AddRange(parameters);
|
|
}
|
|
|
|
using (OracleDataAdapter da = new OracleDataAdapter(cmd))
|
|
{
|
|
using (DataSet ds = new DataSet())
|
|
{
|
|
da.Fill(ds);
|
|
foreach (DataTable table in ds.Tables)
|
|
{
|
|
dts.Add(table);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
connection.Close();
|
|
|
|
return dts;
|
|
}
|
|
}
|
|
}
|