user17452759
user17452759

Reputation:

How to add the filter in Odata?

I just filter all record but I can`t filter one record. enter image description here

[HttpGet("GetContact")]
       
public async Task<ActionResult<IEnumerable<ContactEm>>> GetContactEms([FromQuery(Name = "top")] int top, [FromQuery(Name = "$skip")] int skip, [FromQuery(Name = "$orderby")] string orderny, [FromQuery(Name = "$filter")] string filter)
{
    return await _context.ContactEms.ToListAsync();
}

Upvotes: 0

Views: 158

Answers (1)

pil0t
pil0t

Reputation: 2185

For the "switching on" filtering feature, supported by OData ($filter=...) you should create a controller, inherited from ODataController, with [EnableQuery] attribute on the method. Consider using official manual for a detailed walkthrough. In your case, it should be something like:

public class ContactEmsController : ODataController
{
...
    [EnableQuery]
    public IQueryable<ContactEm> Get()
    {
        return _context.ContactEms;
    }
}

Upvotes: 1

Related Questions