asp.net web api - Filter Child Property OData and ASPNET WebApi -
i'm facing problem. i've googled lot , searched in here too, couldn't find answer problem.
i have aspnet web api
returns json
. also, add microsoft.data.odata nuget allow odata queries.
it's working fine simple cases, now, need apply filter in child collection.
sample:
{"total":1,"products":[{"id":20289,"brandid":5,"categoryid":1,"price":12.0,"name":"carolina herrera","description":"ch","productcode":"asd2334","picture":null,"contentpackaging":"liquid","brandname":"carolina herrera","brandpicture":null,"generic":true}, {"id":20290,"brandid":5,"categoryid":1,"price":25.0,"name":"carolina herrera 2","description":"ch 2","productcode":"asd999","picture":null,"contentpackaging":"liquid","brandname":"carolina herrera","brandpicture":null,"generic":true} ]}
i want query in products collection price greater 20 example.
i've tried this:
http://domain.com/api/$filter=products/price gt 20
but didn't work.
is possible that?
code:
//controller public iqueryable<viewmodelproducts> getproducts() { var products = _repository.findby(x=>x.generic && x.status).tolist(); return products.count == 0 ? new list<viewmodelproducts>().asqueryable() : products.asqueryable(); } //model public class viewmodelproducts { public int total { get; set; } public iqueryable<products> products { get; set; } } public class products { public int id { get; set; } public int brandid { get; set; } public int categoryid { get; set; } public decimal price { get; set; } public string name { get; set; } public string description { get; set; } public string productcode { get; set; } public string picture { get; set; } public string contentpackaging { get; set; } public string brandname { get; set; } public string brandpicture { get; set; } public bool generic { get; set; } }
Comments
Post a Comment