RepoDB
RepoDB copied to clipboard
Bug: `NullReferenceException` occurs during `BulkMerge()`
Bug Description
I get an Object reference not set to an instance of an object error when calling BulkMerge() (I haven't tried other methods).
I have tried calling both .BulkMerge<XXX>(data) (with a class mapping setup: ClassMapper.Add<XXX>("[dbo].[dbTableName]");) and .BulkMerge("dbTableName", data), where data is a DataTable that has been created from XXX.class objects.
Notably, I don't have any attribute mappings (I presume RepoDB can default map types like int, data, string, etc.).
(I suspect the problem is something fairly obvious on my end).
Exception Message:
Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
SqlConnectionExtension.BulkMergeInternalBase[TSqlBulkCopy,TSqlBulkCopyOptions,TSqlBulkCopyColumnMappingCollection,TSqlBulkCopyColumnMapping,TSqlTransaction](DbConnection connection, String tableName, DataTable dataTable, IEnumerable`1 qualifiers, Nullable`1 rowState, IEnumerable`1 mappings, TSqlBulkCopyOptions options, String hints, Nullable`1 bulkCopyTimeout, Nullable`1 batchSize, Nullable`1 isReturnIdentity, Nullable`1 usePhysicalPseudoTempTable, TSqlTransaction transaction)
SqlConnectionExtension.BulkMergeInternal(SqlConnection connection, String tableName, DataTable dataTable, IEnumerable`1 qualifiers, Nullable`1 rowState, IEnumerable`1 mappings, Nullable`1 options, String hints, Nullable`1 bulkCopyTimeout, Nullable`1 batchSize, Nullable`1 isReturnIdentity, Nullable`1 usePhysicalPseudoTempTable, SqlTransaction transaction)
SqlConnectionExtension.BulkMerge(SqlConnection connection, String tableName, DataTable dataTable, IEnumerable`1 qualifiers, Nullable`1 rowState, IEnumerable`1 mappings, Nullable`1 options, String hints, Nullable`1 bulkCopyTimeout, Nullable`1 batchSize, Nullable`1 isReturnIdentity, Nullable`1 usePhysicalPseudoTempTable, SqlTransaction transaction)
Schema and Model:
Model
public class XXX
{
public string? dealingCapacity { get; set; }
public string? exchange { get; set; }
public decimal? executedPrice { get; set; }
public decimal? executedQuantity { get; set; }
public DateTime? executedTimestampUtc { get; set; }
public int fillId { get; set; }
public string? lastLiquidity { get; set; }
public int placementId { get; set; }
public string? tranType { get; set; }
public int? version { get; set; }
}
Schema
The SQL schema is identical (names are identical). In terms of types, nvarchar(100) equates to C# strings and the identical SQL types are used for C# decimal, int and DateTime.
Library Version:
RepoDb v1.12.9 RepoDb.SqlServer v1.1.4 RepoDb.SqlServer.BulkOperations v1.1.5
It sounds basic, probably just a method overload calls. We will investigate and get back to you.
To speedup the investigations, can you as well share the table schema SQL script here? (Just rename the table if you would like)
USE [ZZZ]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[dbTableName](
[dealingCapacity] [nvarchar](1) NULL,
[exchange] [nvarchar](100) NULL,
[executedPrice] [decimal](18, 0) NULL,
[executedQuantity] [decimal](18, 0) NULL,
[executedTimestampUtc] [datetime] NULL,
[fillId] [int] NOT NULL,
[lastLiquidity] [nvarchar](100) NULL,
[placementId] [int] NOT NULL,
[tranType] [nvarchar](100) NULL,
[version] [int] NULL,
CONSTRAINT [PK_DERIV_FILL] PRIMARY KEY CLUSTERED
(
[fillId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
We will get back to you with this. Thanks a lot.
Reopening this issue as the PR #985 is for #963.
Hi, we have spent time replicating this issue, but, it is unfortunate that we could not replicate this.
As a response, we created a small project as a simulation of your end to further start the investigation there.
It is working on the mentioned versions (RepoDb v1.12.9, RepoDb.SqlServer v1.1.4, RepoDb.SqlServer.BulkOperations v1.1.5), and also on the latest beta version of RepoDB (RepoDb v1.12.10-beta4, RepoDb.SqlServer v1.1.5-beta4, RepoDb.SqlServer.BulkOperations 1.1.6-beta2). Please also note that it also workds on the latest main branch.
Would you be able to modify this small project/solution and replicate the issue and revert to us?