Is there anyway to customize the Query expression tree before it's executed against the IQueryable data source in the Controller?
Im assuming this is currently done inside the ComboDataSourceAction attribute, and it uses the values from the QueryString on the filter parameter.
I need to customize the query because I want to leverage LinqToEntities against multiple fields in a database table.
Thanks.
Jean
Hi Jean,Yes, you are are correct that the data transformations on the source data (IQueryable) are done by the logic behind the ComboDataSourceAction attribute. Thus, if you wish to alter the IQueryable before these transformations take place, simply do the necessary changes inside the controller action that's marked with this attribute.Allow me to demonstrate using the sample controller action from the http://es.infragistics.com/products/jquery/sample/combo-box/auto-suggest-and-filtering sample:
[ComboDataSourceAction] [ActionName("filtering-data")] public ActionResult ComboGetData() { var ds = this.DataRepository.GetDataContext().Products; // TODO alter the ds as you wish - the ComboDataSourceAction attribute will transform it further afterwards. return View(ds); }
If you had something else in mind, please provide us with a sample of the alteration that you wish to carry out so we can try and help you out.Thanks!
PS: The ComboDataSourceAction attribute is actually an ActionFilter so these articles may aid you in understanding it:Filtering in ASP.NET MVCAction Filtering in ASP.NET MVC Applications
Thank you for the reply.
I managed to get the behaviour I needed by writing the following code inside the controller Method: Is this the only way to intercept the filter behaviour?
(Note, FullName is a derived Property on Product(i.e. Name1 + " " + Name2)).
Thanks again for your help.
NameValueCollection col = this.HttpContext.Request.QueryString; if (!col.AllKeys.Contains("filter(FullName)")) return View(new List<Product>()); string filterArgs = col["filter(FullName)"].Substring(9).Replace(")", String.Empty).ToLowerInvariant(); var ds = products.Where(p => p.Name.ToLowerInvariant().StartsWith(filterArgs) || p.Name2.ToLowerInvariant().StartsWith(filterArgs));
Parsing the query string parameters and looking through the filter expressions seems good enough to me (in this case).I see that you wish to intercept filtering for the FullName column and handle it yourself so that you can do the custom filtering logic and then pass the new IQueryable to the grid's logic.So if someone else from the community can point out a better solution, that'd be great.