Microsoft.Data.SqlClient.SqlBulkCopy 的两个构造函数之间有什么区别吗?
Is there any difference between two constructors of the Microsoft.Data.SqlClient.SqlBulkCopy?
Microsoft.Data.SqlClient.SqlBulkCopy
类型有四个构造函数:
public SqlBulkCopy(SqlConnection connection);
public SqlBulkCopy(string connectionString);
public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions);
public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, SqlTransaction externalTransaction);
调用public SqlBulkCopy("someConnectionString")
和调用public SqlBulkCopy("someConnectionString", SqlBulkCopyOptions.Default)
有什么区别吗?
不,没有区别。
字段 _copyOptions
没有设置值:https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs#L183
表示默认值为0(相当于SqlBulkCopyOptions.Default
):https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs#L14
构造函数public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions);
调用public SqlBulkCopy(string connectionString);
构造函数并设置_copyOptions
字段:https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs#L309
所以你会得到完全相同的行为
Microsoft.Data.SqlClient.SqlBulkCopy
类型有四个构造函数:
public SqlBulkCopy(SqlConnection connection);
public SqlBulkCopy(string connectionString);
public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions);
public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, SqlTransaction externalTransaction);
调用public SqlBulkCopy("someConnectionString")
和调用public SqlBulkCopy("someConnectionString", SqlBulkCopyOptions.Default)
有什么区别吗?
不,没有区别。
字段 _copyOptions
没有设置值:https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs#L183
表示默认值为0(相当于SqlBulkCopyOptions.Default
):https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs#L14
构造函数public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions);
调用public SqlBulkCopy(string connectionString);
构造函数并设置_copyOptions
字段:https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs#L309
所以你会得到完全相同的行为