Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InsertIfDoesntExist #20

Open
CactusPie opened this issue Sep 18, 2019 · 0 comments
Open

InsertIfDoesntExist #20

CactusPie opened this issue Sep 18, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@CactusPie
Copy link

CactusPie commented Sep 18, 2019

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');
@mtanneryd mtanneryd added enhancement New feature or request and removed enhancement New feature or request labels May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants