Skip to content

Commit

Permalink
提交代码
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanwj committed Jul 30, 2024
1 parent 48fec96 commit ef8f491
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/SmartSql.Bulk.Oracle/BulkInsert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,49 @@
using System.Threading.Tasks;
using System.Linq;
using System.Data;
using Oracle.ManagedDataAccess.Client;

namespace SmartSql.Bulk.Oracle
{
public class BulkInsert : AbstractBulkInsert
{
public BulkInsert(IDbSession dbSession) : base(dbSession)
{
}


private void InsertImpl()
{
var conn = DbSession.Connection as OracleConnection;

using (OracleTransaction transaction = conn.BeginTransaction())
{
//创建 OracleBulkCopy 对象,并指定数据库连接信息
using (OracleBulkCopy bulkCopy = new OracleBulkCopy(conn))
{
//数据库表名称
bulkCopy.DestinationTableName = this.Table.TableName;
//指定批量插入的行数
bulkCopy.BatchSize = this.Table.Rows.Count;

//指定 DataTable 和数据表的列名映射关系
for (int i = 0; i < this.Table.Columns.Count; i++)
{
bulkCopy.ColumnMappings.Add(this.Table.Columns[i].ColumnName, this.Table.Columns[i].ColumnName);
}
try
{
//将数据源添加到 OracleBulkCopy 对象中
bulkCopy.WriteToServer(this.Table);
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
throw;
}
}
}
}

public override void Insert()
Expand All @@ -19,11 +54,6 @@ public override void Insert()
InsertImpl();
}

private void InsertImpl()
{

}

public override async Task InsertAsync()
{
await DbSession.OpenAsync();
Expand Down
4 changes: 4 additions & 0 deletions src/SmartSql.Bulk.Oracle/SmartSql.Bulk.Oracle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.180" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SmartSql.Bulk\SmartSql.Bulk.csproj" />
</ItemGroup>
Expand Down

0 comments on commit ef8f491

Please sign in to comment.