Retrieving Roles with Empty Permission Arrays in Entity Framework Core Repository
When I use this repository it returns the records correctly, except for the records where the Permissions array is empty, it should also return these cases.
When I use instead of it returns me those in which Permissions is empty but it does not return the roles in which I deleted any RolePermissions records.
4 Replies
Because
All()
returns true for an empty sequence, Any()
will return falseso how can I do it to return the correct values??
Github Copilot gave me this suggestion. It works, but it's very big and has some null reference alerts:
why not modify your original query and do
(!r.RolePermissions.Any() || <your_original_Any()_filter>)
in theory that should match any row with empty RolePermissions
and, if not empty, match against your filterthanks