Using OData, how can I make this filter?
My class:
public class Aviso
{
public int Id { get; set; }
public virtual ICollection<User> Destinatarios { get; set; }
public string Url { get; set; }
}
THE uri attempt: /odata/avisos?$filter=(Destinatarios eq null or Destinatarios/count eq 0 or Destinatarios/any(it:it/Id eq 4) )
The goal is to return where any Destinatarios
are 4 or collection is empty (or null).
The Open Data Protocol (OData) enables the creation of REST-based data services, which allow resources, identified using Uniform Resource Identifiers (URIs) and defined in a data model, to be published and edited by Web clients using simple HTTP messages.
You can use filter expressions in OData requests to filter and return only those results that match the expressions specified. You do this by adding the $filter system query option to the end of the OData request.
If you have an on-premise system, then call /N/IWFND/MAINT_SERVICE, choose your service, click on Gateway Client, set the protocol to HTTPS and you'll see the full URL. If you don't then HTTPS isn't configured for your system --> call SMICM, Goto (from menu), Services and check the Host and Port columns in HTTP row.
The $value option is used to get individual properties of an Entity. There are two ways to get individual properties from an entity. We can get the response in either OData format or get the raw value of the property. We need to add method to the controller named GetProperty here property is a name of the property.
Try,
/odata/avisos?$filter=not Destinatarios/any() or Destinatarios/any(d: d/Id eq 4)
You do not need the null check as we handle null propagation for you. Also, having null collections is not a good practice in general as it causes confusion between null and empty collections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With