Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

bug when using contains on a literal which matches property name #106

Closed graphicsxp closed 3 years ago

graphicsxp commented 3 years ago

The following is using Breeze Server .net Core 3 Please consider the following odata query from client : image

The following code in BaseBlock.cs considers that "id" is not a literal because it matches a property name of the entity. It is correct that this entity has a property "id", however this is clearly a bug because we are only trying to filter entities for which a property "Prefix" matches the literal "id". If we send exactly the same query with another string, it works just fine.

image

Can this be fixed please ?

EDIT : I had a look in the .Net 5 version and I'm guessing there is the same issue because the code is identical : https://github.com/Breeze/breeze.server.net/blob/beb62367f2088759149ff3c1ec97de41cad5d3b7/AspNetCore-v5/Breeze.Core/Query/BaseBlock.cs#L62

steveschmitt commented 3 years ago

Yes, here Breeze says, "if the right-hand-side of the expression happens to match a property name, then assume you meant the property instead of the value". This works most of the time, but with short property names like "id", it can be a problem.

The solution is to be explicit it in your query, by telling Breeze that you are passing a value on on the right-hand side of the expression:

{"where":{"Prefix":{"contains":{"value":"id","dataType":"String"}}}}

Then the server will know exactly what you mean.

graphicsxp commented 3 years ago

@steveschmitt Thanks a lot, it works :)

if you have a chance, I'd appreciate a reply to my other questions on this thread https://github.com/Breeze/breeze.server.net/issues/103 . I had reported a number of issues with the .net core 3 version and it seems the fix were not merged with the new .net core 5 version.