Hi,
Did anyone write a translator from an UltraGrid column filter(s) to a Linq Expression? Are any of you aware of such a thing?
Any advise before I jump into it?
Regards,
Hernán.
Hello Hernan,
There is no automatic way to achieve this nor do we have a translator that I am aware of. Let me know if you have any additional questions regarding this matter.
Michael DiFilippo said: There is no automatic way to achieve this nor do we have a translator that I am aware of. Let me know if you have any additional questions regarding this matter.
I thought so, that's why I asked here in the forums instead of placing a support request in case any other user had already done it before.
The rationale is to have a mechanism for server-side filtering by means of a standard API that could work across SQL and NoSQL data stores.
Anyway, now I believe it's doable by myself. I've just found an old Microsoft example (Dynamic Linq, see http://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library) which translates a string expression written in a custom mini-language into a Linq Expression. Hence, one solution could consist in converting the UltraGrid.ColumnFilterCollection to the mini-language string and then into a Linq Expression by using the MS Dynamic Linq.
Of course you can avoid the mini-language step altogether by modifying the MS example and going straight from the UG.ColumnFilterCollection to Linq but that would require to dig into an old and uncommented MS source code.
Hello and thank you for following up. Glad to hear you found some leeway on this matter. Let us know if you have any additional questions regarding the UltraGrid.
Ok, here's a proof of concept.
I've implemented just a few of the logical operators (==, >, Contains, StartsWith) and only the "and" connector but those are enough to show how it could be done. It converts an Infragistics.Win.UltraWinGrid.ColumnFiltersCollection into a DynamicLinq predicate along with its parameter values. Then applies the predicate directly to the IQueryable data source to filter the data at server-side using a suitable Linq provider.
The DynamicLinq classes and extensions are available at several locations but it seems that the "official" is the System.Linq.Dynamic package at NuGet repositories.
The attached solution doesn't include DLLs, so you need to run "Install-Package System.Linq.Dynamic" at the Package Manager Console prompt before compiling the solution.
Extending the supported logical operators to the full list is straight forward.