I'm trying to insert a large set of objects into the table but I don't have any efficient way to check if some records aren't already there. Every time I use this:
using Z.EntityFramework.Extensions.Core;
...
await ac.BulkInsertAsync(query, (o) => { o.?? });
it just stops the insert each time it finds a duplicate. Is there a way to either run all queries at once without it just stopping at the first error, or outright applying IGNORE
?
You should check the InsertIfNotExists options. Only records that don't already exists will be inserted.
using Z.EntityFramework.Extensions.Core;
...
await ac.BulkInsertAsync(query, (o) => { o.InsertIfNotExists = true });
ANSWER Sub-Question
I have an UNIQUE key in my table on one of the fields. How do I set it for bulk operations?
You can customize the key with the ColumnPrimaryKeyExpression option.
ctx.BulkInsert(list, options =>
{
options.ColumnPrimaryKeyExpression = x => new { x.ColumnKey1, x.ColumnKey2 };
options.InsertIfNotExists = true;
});