zzzprojects / Bulk-Operations

C# SQL Bulk Operations | High-performance C# bulk insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL, and SQLite.
https://bulk-operations.net
142 stars 36 forks source link

Primary Key not Present in Dictionary #40

Closed svernyi closed 5 years ago

svernyi commented 5 years ago

Hello!

I have a MySQL Bulk Insert operation. The primary key is a composite key of { PartyId, PartySourceSystemId }.

In my database, I have a pre-insert trigger that takes care of assigning the primary key. In other words, I do not explicitly need to set it in my code. image

var parties = (new List<Party>()
{
    new Party
    {
        // PartyId - Primary Key
        PartySourceSystemId = ctx.SourceSystemId, // Primary Key
        PartyTypeId = 1, //Non-nullable FK
        PartyTypeSourceSystemId = 1, //Non-nullable FK
        PartyKey = Guid.NewGuid() // Non-nullable
    }
});

try
{
    ctx.BulkInsert<Party>(parties, opts =>
        {
            opts.CaseSensitive = CaseSensitiveType.Insensitive;
        });
}

This results in the exception above. I can resolve this by manually mapping out the columns --

ctx.BulkInsert<Party>(parties, opts =>
    {
        opts.CaseSensitive = CaseSensitiveType.Insensitive;
        opts.ColumnMappings.Add(a => a.PartyId, true);
        opts.ColumnMappings.Add(a => a.PartySourceSystemId, true);
        opts.ColumnMappings.Add(a => a.PartyKey, false);
        opts.ColumnMappings.Add(a => a.PartyTypeId, false);
        opts.ColumnMappings.Add(a => a.PartyTypeSourceSystemId, false);
    });

But now I have to manually map out every column every time I use BulkInsert. Is there a better way?

Thanks!!!

JonathanMagnan commented 5 years ago

Hello @svernyi ,

Thank you for reporting. I will assign this issue to my developer.

We will look at it to make sure we understand the current issue.

Best Regards,

Jonathan

JonathanMagnan commented 5 years ago

Hello @svernyi ,

Sorry for the long waiting.

The EF Extensions v3.16.27 has been released to support Case Insensitive.

I recommend you to use "opts.CaseSensitive = CaseSensitiveType.DestinationInsensitive;" since the source already matches, only the destination might be different.

Let me know if everything is working as expected.

Best Regards,

Jonathan

svernyi commented 5 years ago

Hey @JonathanMagnan , thanks for the update!

Does this also apply to the Z.EntityFramework.Extensions.EFCore package?

JonathanMagnan commented 5 years ago

Hello @svernyi ,

I do not believe since it has not been released. I will add a task to my developer to look at it.

JonathanMagnan commented 5 years ago

Hello @svernyi ,

The v2.1.53 has been released for EF Core.

Let me know if that work as expected.

Best Regards,

Jonathan