Skip to content

Commit 8fd621d

Browse files
committed
Clarify generated command ownership
1 parent f45fee1 commit 8fd621d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎samples/MoviesAppSample/DataAccess/PersonDal.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private ValueTask<bool> SaveMoviePersonsAsync(SQLiteDbContext context, string ta
108108
DbType.Int64.CreateInputParam("@MovieId", movieId));
109109
//table.PrimaryKey = new[] { table.Columns["MovieId"], table.Columns["PersonId"] };
110110
using (adapter)
111-
using (var builder = new SQLiteCommandBuilder(adapter))
111+
using (var commandBuilder = new SQLiteCommandBuilder(adapter))
112112
{
113113
var processedRows = new HashSet<DataRow>();
114114
foreach (var dto in dtos)
@@ -134,7 +134,13 @@ private ValueTask<bool> SaveMoviePersonsAsync(SQLiteDbContext context, string ta
134134
{
135135
num = ctx.Connection.Update(adapter, table, cancellationToken);
136136
}
137+
138+
// The builder generates insert/update/delete commands lazily and caches them.
139+
// Detaching it from the adapter calls RefreshSchema, which disposes these commands.
140+
commandBuilder.DataAdapter = null;
141+
137142
table.ClearAndDispose();
143+
138144
return num > 0;
139145
}
140146
}, cancellationToken);

0 commit comments

Comments
 (0)