-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support 'contains' for nested collections #277
Comments
First up, this is essential, but I don't think that 'contains' is the right operator. I would prefer to see the collection annotated as such, and normal operators used - for example for a person object with a collection of tasks
to get open tasks. The reason for this is that it provides full access to all operators. Also, it ensures that grouping is available with the original intent. For example, if you apply two contains operators to the same collection, it is unclear whether you want records where the collection contains at least one object meeting each condition separately, or the same object meeting both conditions. In contrast, the following is unambiguous.
Anyway, it turns out that this is also far easier and more concise to code. If you replace your FilterExpressionCompiler with the following, then filtering by nested collections works. It would be great if you could tidy it up as you require and integrate this into the code base. Anyone else can feel free to use it.
|
Hello @statler Your suggestion is to extend the filter expression syntax so that [ "Tasks[].DateActioned", "<>", null ] is translated into Tasks.Any(i => i.DateActioned != null) Adding such a new syntax is a more broad task, because it's used not only in this library but across the entire DevExtreme Data Layer (docs). My idea is that if you can encapsulate a condition in a calculated property: public bool HasActionedDate {
get { return Tasks.Any(i => i.DateActioned != null); }
} - or describe a helper collection of primitives: public IEnumerable<DateTime?> TaskActionedDates {
get { return Tasks.Select(i => i.DateActioned); }
} then you can use filter capabilities that are currently supported or that are candidates for implementation. |
@AlekseyMartynov, any progress on it? We need support search on collection of objects (also filtering if possible) P.s. I've tried to implement it on backend by reading Filter value, then I searched for target collection, apply contains (or not contains) filter and remove it from the filter. But it's quite complicated when search and grouping applied to table (in this case Filter item is array of arrays). |
@Bykiev |
@AlekseyMartynov, thx! I've a Product which can be manufactured by multiple factory. So, I have one-to-many relation between Product and Factory tables. I need to display products table with manufacturers (right now I'm using calculateCellValue method to display factory names in one column separated by comma). Because of it, I need to search on collection of objects (allow contains/notcontains search), which is not supported by DevExtreme.AspNet.Data library. |
In the context of this ticket, we plan to support search in collections of values (tags, keywords, numbers, etc). For example:
Search in a one-to-many collection, if I understand your requirements correctly, is an analog of LINQ _nwind.Categories.Where(c => c.Products.Any(p => p.ProductName.Contains("che"))); To add this, we first need to extend DevExtreme filter expression syntax. If you share a runnable sample project (here or via Support Center), we can come up with a quick workaround for your specific case. |
@AlekseyMartynov, you're right, this LINQ query example is exactly what I need.
If the property type is number 'equal', 'not equal', 'greater' and 'lower' filter should be supported:
I'll provide a runnable example tomorrow via support center and link back here |
@AlekseyMartynov, my collegue posted a runnable sample with this issue on support center: https://www.devexpress.com/Support/Center/Question/Details/T745959 |
Version 2.3.0 introduces a new API to intercept and customize the translation of filter parts. Check code samples in the release notes. |
@AlekseyMartynov, thank you! |
Sorry, but I have to say it: This was one of the best extensions idea !!! It helped me in many situations! |
@Franki1986
Great! I know that |
Yes.. I am still experimenting to check all error cases but with using System.LinqDynamic.Core:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Our Support Team will address your questions in the context of your ticket (ID T848079). I kindly ask you to avoid cross-posting issues in the future. This will save time and allow us to process all your inquiries in the most efficient manner. |
I wrote a neat little helper for this that allows the use of dot notation on collections for any collection on the object. Figured others would probably find it useful. This is for querying across a many:many relationship. Saves a mountain of code and genericises this method significantly. Use with annotation like on the orders collection to get all orders containing any product with id 184, of products with Id 184 or 189,
Register a CustomFilter like this
|
@statler Your solution is very helpful, thanks for sharing. Any chance for support for contains? e.g. matching is there is a ProductName that contains 'ba' instead of if a Product name equals 'ba'? ["ProductOrders.ProductName","contains","ba"] |
You just need to modify the else clause
and change anyPredicate so it tests for contains instead of equality. A google search will help out here - I am on the road for a week or so, so cant give specifics as I am stretched for time - but hopefully that points you in the right direction |
Requested by DevExtreme users:
Potentially useful for non-relational LINQ providers (Mongo, etc).
The text was updated successfully, but these errors were encountered: