abp
abp copied to clipboard
When can ExecuteUpdate and ExecuteDelete be extended on Queryable?
Is there an existing issue for this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
In the document of EF Core 7, I found the chapter 'Efficient Update'. Currently, if I want to use it in the Domain and Application layers.
Describe the solution you'd like
I need to customize a Repository. I wonder if this can be extended to include an ExecuteUpdate and ExecuteDelete method on Queryable. Of course, ExecuteDelete needs to be combined with ISoftDelete
Additional context
No response
Have you reviewed this document ?
Yes, it was my negligence. I checked again and saw the direct deletion operation, but there was no direct batch update operation. The batch update in the document still needs to extract all Entities and update them, rather than updating them based on Queryable. The problem now is that if I need to update objects larger than 1000 or more, the server's memory may not be able to hold up, so I need to update such operations directly in the EF Core. Is it because of the issue of entity tracking that this operation was intentionally not opened?
My current approach is to batch these update operations into backgroundjob to save server resource usage. So I hope there is a simpler method.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@hemiaoio You can do ExecuteDelete and ExecuteUpdate in "EntityFrameworkCore" Project. Not Application project. The reason is, ExecuteDelete and ExecuteUpdate is uses "Microsoft.EntityframeworkCore" namespace. And Application layer doesn't has, shouldn't has it.
So creating a custom repository is the solution.
public class CustomTableARepositry : EfCoreRepository<DbContext, CustomTableA, Guid>, repositoryInterface
IQueryable<CustomTableA> repostitory = await GetQueryableAsync();
IQueryable<CustomTableA> repostitoryWheredQuery = repostitory.Where(yourWhereQuery);
repostitoryWheredQuery.ExecuteUpdate(setters => setters.SetProperty(b=> b.IsDeleted, true));
@maliming FYI