mtanneryd/ef-bulk-operations

InsertIfDoesntExist

CactusPie opened this issue · 0 comments

Would it be possible to implement a method that inserts a new records if it doesn't exist based on a specified key. Essentially something like:

_context.BulkUpdateAll(new BulkUpdateRequest
{
     Entities = new[] {new User {UserName = "someUserName}},
     InsertIfNew = true,
     KeyPropertyNames = new[] {"UserName"},
     UpdatedColumnNames = new[] {"UserName"},
     Transaction = null
});

Except that doesn't work, since all UpdatedColumnNames that also exist in KeyPropertyNames are filtered out. Update isn't even needed here, for every entity in the list we would only need:

 IF NOT EXISTS(SELECT 1 FROM Users x where x.UserName = 'someUserName')
  INSERT INTO Users(UserName) VALUES ('someUserName');