abp icon indicating copy to clipboard operation
abp copied to clipboard

When can ExecuteUpdate and ExecuteDelete be extended on Queryable?

Open hemiaoio opened this issue 1 year ago • 5 comments

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

hemiaoio avatar Jul 05 '23 02:07 hemiaoio

Have you reviewed this document ?

muhlisatac avatar Jul 13 '23 11:07 muhlisatac

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?

hemiaoio avatar Jul 17 '23 09:07 hemiaoio

My current approach is to batch these update operations into backgroundjob to save server resource usage. So I hope there is a simpler method.

hemiaoio avatar Jul 17 '23 09:07 hemiaoio

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.

stale[bot] avatar Sep 17 '23 00:09 stale[bot]

@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

ugurozturk avatar Jan 03 '24 12:01 ugurozturk