Recreates Github issue 610: BulkInsertOrUpdateAsync fails when PK is long.
- Run schema.sql to create test tables.
- Update the connection string in UnitTest1.cs.
- Run all tests. Use debug to see SQL output to console.
Example string PK SQL:
MERGE [dbo].[RevenueScheduleString] WITH (HOLDLOCK) AS T
USING (
SELECT TOP 10 *
FROM [dbo].[#RevenueScheduleStringTemp4bed81fc]
ORDER BY [RevenueScheduleId]
) AS S
ON T.[RevenueScheduleId] = S.[RevenueScheduleId]
WHEN NOT MATCHED BY TARGET THEN INSERT
-- RevenueScheduleId is in the merge statement when PK is string
([RevenueScheduleId], [BatchId]) VALUES (S.[RevenueScheduleId], S.[BatchId])
WHEN MATCHED AND EXISTS (SELECT S.[RevenueScheduleId], S.[BatchId] EXCEPT SELECT T.[RevenueScheduleId], T.[BatchId]) THEN UPDATE SET T.[BatchId] = S.[BatchId];Example long PK SQL:
MERGE [dbo].[RevenueScheduleLong] WITH (HOLDLOCK) AS T
USING (
SELECT TOP 10 *
FROM [dbo].[#RevenueScheduleLongTempd17e5168]
ORDER BY [RevenueScheduleId]
) AS S
ON T.[RevenueScheduleId] = S.[RevenueScheduleId]
-- RevenueScheduleId is missing
WHEN NOT MATCHED BY TARGET THEN INSERT ([BatchId]) VALUES (S.[BatchId])
WHEN MATCHED AND EXISTS (SELECT S.[BatchId] EXCEPT SELECT T.[BatchId]) THEN UPDATE SET T.[BatchId] = S.[BatchId];