Base solution for your next web application
Open Closed

Implementation of BulkUpdateAsync() #11848


User avatar
0
huntethan89 created

Hi, I was implementing the BulkUpdateAsync() method to update entities based on the condition but didn't find a way to implement it while passing parameters updateExpression and predicate. Could you please help me with this with an example?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @huntethan89

    Could you share your current implementation ? Or where you want to implement this ?

  • User Avatar
    0
    huntethan89 created

    Hi, I am using BatchDeleteAsync() to delete multiple rows in table based on the condition in predicate, but it will hard delete all rows. Please check the below screenshot.

    I want to soft-delete the same by setting IsDeleted = 1. I can use DeleteAsync method but it's for the single entity and needs loop for the condition-based deletion. I found the method BatchUpdateAsync() which can be used to update multiple rows based on predicate. So, I just want to know how it can be implemented in place of the above attached query. I am getting issues while setting the predicate and update expression in its parameters.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use something like below. This statement updates IsDeleted field of all roles.

    await _roleRepository.BatchUpdateAsync(r => new Role {IsDeleted = true}, r => r.Id > 0);