From 2dbcd827a8194963a055335d2837a4251ae7596b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 15 Mar 2026 07:20:39 +0000 Subject: [PATCH 1/2] fix: exclude computed columns from BulkCopy column mappings (Closes #272) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SqlBulkCopy sends all DataTable columns to SQL Server by default. Computed (PERSISTED) columns are marked ReadOnly in the DataTable schema (via is_computed flag from sys.columns), but SQL Server rejects any write to a computed column — causing 'The column cannot be modified because it is either a computed column or is the result of a UNION operator.' Fix: build explicit ColumnMappings from the non-ReadOnly columns before calling WriteToServer. Identity columns follow the same rule: they are excluded unless the caller opts in with SqlBulkCopyOptions.KeepIdentity, which already was the implicit SqlBulkCopy default behaviour when no ColumnMappings are present. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/SqlClient/DataTable.fs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SqlClient/DataTable.fs b/src/SqlClient/DataTable.fs index 03a6a8da..1948ea6c 100644 --- a/src/SqlClient/DataTable.fs +++ b/src/SqlClient/DataTable.fs @@ -111,6 +111,13 @@ type DataTable<'T when 'T :> DataRow>(selectCommand: SqlCommand, ?connectionStri bulkCopy.DestinationTableName <- this.TableName batchSize |> Option.iter bulkCopy.set_BatchSize timeout |> Option.iter (fun x -> bulkCopy.BulkCopyTimeout <- int x.TotalSeconds) + // Exclude computed columns (ReadOnly=true, AutoIncrement=false) because SQL Server + // rejects writes to computed columns. Also exclude identity columns unless the + // caller explicitly opted in with KeepIdentity. + let keepIdentity = options.HasFlag(SqlBulkCopyOptions.KeepIdentity) + for col in this.Columns |> Seq.cast do + if not col.ReadOnly || (col.AutoIncrement && keepIdentity) then + bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName) |> ignore bulkCopy.WriteToServer this #if WITH_LEGACY_NAMESPACE From f477045ac56cd653316adf7f51014e5e091bb8c0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 15 Mar 2026 07:26:40 +0000 Subject: [PATCH 2/2] ci: trigger checks