You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicclassProduct{publicvirtualintId{get;set;}publicvirtualIList<ProductFieldValue> FieldValues {get;set;}=newList<ProductFieldValue>();}publicclassProductFieldValue{publicvirtualProductProduct{get;set;}publicvirtualFieldField{get;set;}publicvirtualstringValue{get;set;}// This is a comma separated list of values.}publicclassField{publicvirtualintId{get;set;}}
I'd lke to retrieve a list of products filtered by the field values. For example say I have the following dictionary to filter against (where the key is the field id and the value is the values I'd like to filter by):
varquery= _session.Query<Product>();foreach(var field in filters){foreach(var value in field.Value){query= query.Where(p => p.FieldValues.Any(fv => fv.Field.Id == field.Key &&(fv.Value.StartsWith(value+",")|| fv.Value.Contains(", "+value+",")|| fv.Value.EndsWith(", "+value)|| fv.Value.Equals(value))));}}varresults=await query.ToListAsync();
Whilst this executes fine, it will only returns back a matching product if it matches every potential value in the filter. Using the example above it would only return back products which matched both "A" and "B". Ideally I'd like this to match any products which match any of the field values. Therefore I changed my query to the following:
However this throws back the error "System.NotSupportedException: ': ( : p2 )'". I'm also slighty concerned about the performance of this.
I know the obvious solution is to add a record in the ProductFieldValue entity's table for each value (instead of using a comma separated list) but unfortunately this is not possible as this structure is set in stone.
If anyone has any further suggestions which will allow me do this filter using LINQ in the most efficient way I'd really appreciate it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My application has the following entities:
I'd lke to retrieve a list of products filtered by the field values. For example say I have the following dictionary to filter against (where the key is the field id and the value is the values I'd like to filter by):
I could say something like:
Whilst this executes fine, it will only returns back a matching product if it matches every potential value in the filter. Using the example above it would only return back products which matched both "A" and "B". Ideally I'd like this to match any products which match any of the field values. Therefore I changed my query to the following:
However this throws back the error "System.NotSupportedException: ': ( : p2 )'". I'm also slighty concerned about the performance of this.
I know the obvious solution is to add a record in the
ProductFieldValue
entity's table for each value (instead of using a comma separated list) but unfortunately this is not possible as this structure is set in stone.If anyone has any further suggestions which will allow me do this filter using LINQ in the most efficient way I'd really appreciate it.
Beta Was this translation helpful? Give feedback.
All reactions