Hi!
I found that BulkCopy(Async) ignores IDataContext.CloseAfterUse option for at least SQL Server. We are mixing Entity Framework and Linq2Db for time of migration from EF. And we want to have same behavior of managing connections as EF does (close right after query completed).
This works fine, but seem BulkCopy ignores this option that leads to distributed transaction, which is very unwanted.
Steps to reproduce
public class Test
{
public int Id { get; set; }
public string Name { get; set; }
}
internal class Context : DataConnection
{
public const string ConnString = "...connection string...";
static Context()
{
SqlServerTools.Provider = SqlServerProvider.SystemDataSqlClient;
}
public Context() : base(LinqToDB.ProviderName.SqlServer2012, ConnString)
{
(this as IDataContext).CloseAfterUse = true; // Very vital for us
}
}
using var scope = new TransactionScope();
using var ctx = new Context();
var t = new List<Test>() { new Test { Id = 55, Name = "test" }, new Test { Id = 355, Name = "ewrwe" } };
ctx.BulkCopy(t);
//ctx.Close(); // this is workaround
var conn = new SqlConnection(Context.ConnString);
conn.Open(); // got error here
var cmd = new SqlCommand("select 1", conn);
cmd.ExecuteNonQuery();
Environment details
Linq To DB version: 5.2.2
Database (with version): SQL Server 20**
ADO.NET Provider (with version): SystemDataSqlClient
Operating system: Windows 10
.NET Version: 7.0
Hi!
I found that
BulkCopy(Async)ignoresIDataContext.CloseAfterUseoption for at least SQL Server. We are mixing Entity Framework and Linq2Db for time of migration from EF. And we want to have same behavior of managing connections as EF does (close right after query completed).This works fine, but seem
BulkCopyignores this option that leads to distributed transaction, which is very unwanted.Steps to reproduce
Environment details
Linq To DBversion: 5.2.2Database (with version): SQL Server 20**
ADO.NET Provider (with version): SystemDataSqlClient
Operating system: Windows 10
.NET Version: 7.0