Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: NullReferenceException occurs during BulkMerge() #964

Open
micycle1 opened this issue Oct 20, 2021 · 5 comments
Open

Bug: NullReferenceException occurs during BulkMerge() #964

micycle1 opened this issue Oct 20, 2021 · 5 comments
Assignees
Labels
bug Something isn't working working-as-expected The reported issue is working as expected.

Comments

@micycle1
Copy link

micycle1 commented Oct 20, 2021

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

@micycle1 micycle1 added the bug Something isn't working label Oct 20, 2021
@micycle1 micycle1 changed the title NullReferenceException during BulkMerge() Bug: NullReferenceException occurs during BulkMerge() Oct 20, 2021
@mikependon
Copy link
Owner

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)

@micycle1
Copy link
Author

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

@mikependon
Copy link
Owner

We will get back to you with this. Thanks a lot.

@mikependon mikependon pinned this issue Nov 9, 2021
mikependon added a commit that referenced this issue Nov 16, 2021
Fix #964 Bug: NullReferenceException occurs during BulkMerge()
@SergerGood SergerGood unpinned this issue Nov 18, 2021
mikependon added a commit that referenced this issue Nov 19, 2021
Fix #964 Removed logic that the ordering fields should be in the select
@mikependon
Copy link
Owner

Reopening this issue as the PR #985 is for #963.

@mikependon mikependon reopened this Dec 1, 2021
@mikependon mikependon pinned this issue Dec 5, 2021
@mikependon
Copy link
Owner

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?

Issue964.zip

@mikependon mikependon added the working-as-expected The reported issue is working as expected. label Dec 20, 2021
@mikependon mikependon unpinned this issue Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working working-as-expected The reported issue is working as expected.
Projects
None yet
Development

No branches or pull requests

2 participants