You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the has function in query string filters takes a single parameter: the target collection. For example:
GET /users?filter=has(roles) HTTP/1.1
This returns the subset of users that are associated with at least one role. Combining this with an include, we can filter the included set of roles to a specific subset:
GET /users?filter=has(roles)&include=roles&filter[roles]=equals(name,'Administrator') HTTP/1.1
This returns the subset of users that are associated with at least one role, then filters the returned roles with name Administrator. The problem is that the resulting subset of customers now may contain an empty set of roles (in case a customer does have a role, but it is not named Administrator).
What we'd like to get instead, is the subset of customers that have at least one role with name Administrator. This proposal enables that by adding an optional condition to the has function, which allows to specify a filter. Then we can write:
GET /users?filter=has(roles,equals(name,'Administrator'))&include=roles&filter[roles]=equals(name,'Administrator') HTTP/1.1
And this returns the subset of users that are associated with at least one role named Administrator, along with only those roles. So no more customers with an empty included set of roles.
Implementation
Currently, the has function translates to the LINQ Any() extension method. An overload of Any() exists that takes a predicate. So if the has function contains the optional condition, we'll call the overload with predicate instead. EF Core translates that to a WHERE EXISTS(...) clause.
The text was updated successfully, but these errors were encountered:
Proposal
Currently, the
has
function in query string filters takes a single parameter: the target collection. For example:This returns the subset of users that are associated with at least one role. Combining this with an include, we can filter the included set of roles to a specific subset:
This returns the subset of users that are associated with at least one role, then filters the returned roles with name Administrator. The problem is that the resulting subset of customers now may contain an empty set of roles (in case a customer does have a role, but it is not named Administrator).
What we'd like to get instead, is the subset of customers that have at least one role with name Administrator. This proposal enables that by adding an optional condition to the
has
function, which allows to specify a filter. Then we can write:And this returns the subset of users that are associated with at least one role named Administrator, along with only those roles. So no more customers with an empty included set of roles.
Implementation
Currently, the
has
function translates to the LINQAny()
extension method. An overload ofAny()
exists that takes a predicate. So if thehas
function contains the optional condition, we'll call the overload with predicate instead. EF Core translates that to aWHERE EXISTS(...)
clause.The text was updated successfully, but these errors were encountered: