Closed ce-kkoziel closed 1 year ago
hi, i've just use this expression my UserQuery like this, I hope it's explain your question,
I have something like this. I have selected entity type and I want bind his Id property to filter value, but filter property is a string type. It is possible?
You could use RestLog.QueryString.Any.Value
EqualsTo
[CurrentEntity].Id
Also using [+ Add Group] with an AND and RestLog.QueryString.Any
as token you could filter by:
Value ([CurrentEntity].Id
).
Maybe this improves performance.
@olmobrutall i was trying like you said.
I have currently concrete entity type selected and filter like this, but still not working.
Client app in default filters do not sends ID rather than this expression.
When I change this value to concrete ID through dev tools and resend the request, executeQuery returns result.
I can not see in the screenshot if you are in a UserQuery or in a SearchControl
If in a UserQuery it should work.
The code that does the [CurrentEntity].Id
evaluation is this one:
@olmobrutall thanks for pointing place in code. We will try to find why it does not work for us.
@olmobrutall The expression is not working when the left operand is a string type value. Then expression "[CurrentEntity].Id" is treated just as a string. In my case the Value property from QueryString is a string, but Entity Id property is Guid.
in your Starter.cs try adding the following:
FilterValueConverter.SpecificConverters.Add(FilterType.String, new CurrentEntityConverter())
Converter is executing for string left operand, but actually [CurrentEntity].Id is PrimaryKey type, and type convertion does not work for string <-> PrimaryKey pair, becouse type converter for PrimaryKey type allow convertion only for int, long, guid.
Unable to convert '2faeeb27-b96b-4588-be67-891776382851' (of type PrimaryKey) to type string
I was trying to use [CurrentEntity].Id.ToString expression but .NET throws AmbiguousMatchException. PrimaryKey have 2 ToString method overloads.
Further, I was trying to use [CurrentEntity].Id.Object.ToString but, PrimaryKey Object is a field.
Finally, I was trying to implement custom IFilterValueConverter implementation based on CurrentEntityConverter and use custom implementation of SimpleMemberEvaluator where evaluator will also check fields, but CurrentEntityConverter have usage of private static currentEntityVariable.
@olmobrutall any other hint how to use it without Framework changes?
Hi @ce-kkoziel, to me looks like this line is not doing its work:
The FilterValueConverter already has a targetType
and the fact that a PrimaryKey
can not be converted to a string is a bug/missing feature.
Feel free to extend the implementation of CanConvertTo
/ ConvertTo
in PrimaryKeyTypeConverter
calling ToString
.
Changing ConvertFrom
/ CanConvertFrom
could be more problematic because you don't have context to know that is the expected value (int, long, Guid)
You don't need to avoid changing the framework at all costs, you can make any reasonable change or create an extension point for the unreasonable ones.
I think this error should not exist since 0cec7f7992602ead8db4a3c663389765cc534390 because now the FilterConverters are registered in a flat list instead of per FilterType
.
Closing the issue.
Dear @olmobrutall ,
Can you explain, or share some documentation, how to use [CurrentEntity] keyword while building custom user queries?
With regards, Kozieł Karol