Hello again geniuses, I want to be able to execute dynamic queries with DO. For example, on a search form, I want the user to be able to pick the type of entity he wants to search. Once he picks the type of entity, I will display a list of the entity's persistent properties. For each persistent property, the user can select among various filter operators (e.g. EQUALS, NOT EQUALS, LESS THAN, GREATER THAN, etc.), and then specify the criteria for that filter. For example, the user can pick the "Customer" entity, and I will display the Name and CompanyName properties available for search. For CompanyName, he can select "EQUALS" and enter "Xtensive" as the filter. I would then like to execute Query.All<customer>().Where(customer => customer.CompanyName == "Xtensive") Would you happen to know how I can do that? Maybe I can do typeof(Query).GetMethod("All").MakeGenericMethod(entityType).GetMethod("Where").MakeGenericMethod(...).Invoke(...) But I would need to pass an expression of type Func<customer, bool=""> to the second call to MakeGenericMethod() and also the actual delegate to Invoke() Is there an easier way? If not, do you have any suggestions for building the expression and delegate? The actual delegate would need to be customer => customer.CompanyName == "Xtensive", or it could be entity => entity[propertyName] == value Thank you! Updated at 16.07.2010 9:30:48Using Dynamic LINQ library... http://weblogs.asp.net/scottgu/archive/ ... brary.aspx
works like a charm. Any better suggestions? This thread was imported from our support forum. The original discussion may contain more detailed answer. |
Likely, no. The idea to develop a general purpose control allowing to visually build such LINQ queries over any LINQ provider lives in my head for pretty long time :) The task is pretty common, but it seems there is still no simple solution. |