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.
55 lines
1.7 KiB
55 lines
1.7 KiB
using System.Data.SqlClient;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SqlSugar.Odbc
|
|
{
|
|
|
|
public class OdbcFastBuilder:FastBuilder,IFastBuilder
|
|
{
|
|
public override bool IsActionUpdateColumns { get; set; } = true;
|
|
public override DbFastestProperties DbFastestProperties { get; set; } = new DbFastestProperties() {
|
|
HasOffsetTime=true
|
|
};
|
|
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
|
{
|
|
|
|
SqlBulkCopy bulkCopy = GetBulkCopyInstance();
|
|
bulkCopy.DestinationTableName = dt.TableName;
|
|
try
|
|
{
|
|
await bulkCopy.WriteToServerAsync(dt);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
CloseDb();
|
|
throw ex;
|
|
}
|
|
CloseDb();
|
|
return dt.Rows.Count;
|
|
}
|
|
public SqlBulkCopy GetBulkCopyInstance()
|
|
{
|
|
SqlBulkCopy copy;
|
|
if (this.Context.Ado.Transaction == null)
|
|
{
|
|
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection);
|
|
}
|
|
else
|
|
{
|
|
copy = new SqlBulkCopy((SqlConnection)this.Context.Ado.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)this.Context.Ado.Transaction);
|
|
}
|
|
if (this.Context.Ado.Connection.State == ConnectionState.Closed)
|
|
{
|
|
this.Context.Ado.Connection.Open();
|
|
}
|
|
copy.BulkCopyTimeout = this.Context.Ado.CommandTimeOut;
|
|
return copy;
|
|
}
|
|
|
|
}
|
|
}
|
|
|