Skip to content

InsertIfDoesntExist #20

@CactusPie

Description

@CactusPie

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');

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions