Variable in where is not being replaced by actual value
davidjohanssonbf opened this issue · 2 comments
davidjohanssonbf commented
What could be wrong here?
I'm using Angular v13.
jinqu-odata version
1.1.3
Steps to reproduce
Do a query where you have a variable instead of an actual string
const searchString = "Apple";
const result = await this.context.fruits
.where(fruit => fruit.name.includes(searchString))
.toArrayAsync();
Expected behavior
http://localhost:9123/fruits?$filter=contains(name%2C'Apple')
Actual behavior
http://localhost:9123/fruits?$filter=contains(name%2CsearchString)
davidjohanssonbf commented
Ah, I see now that I have to use I think something called scopes?
If I do it like this, it works:
const result = await this.context.fruits
.where(fruit => fruit.name.includes(searchString), { searchString: searchString })
.toArrayAsync();
umutozel commented
Yeah, exactly.
We need to parse the function to be able to interpret it and send the request to OData server, so we only have the function as a string, not the scope when the function is called.
Thanks for the feedback.