rsdn / CodeJam

Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
MIT License
258 stars 35 forks source link

QueryableExtensions for ranges generates wrong Expression. #144

Closed sdanyliv closed 2 years ago

sdanyliv commented 2 years ago

This line https://github.com/rsdn/CodeJam/blob/master/CodeJam.Main/Collections/QueryableExtensions.Ranges.cs#L192

generates And but should be AndAlso. It should be not not bit operation but predicate.

NN--- commented 2 years ago

Can you think about failing test case with the current implementation ? Thanks.

https://github.com/rsdn/CodeJam/blob/master/CodeJam.Main.Tests/Collections/QueryableExtensionsTests.cs

sdanyliv commented 2 years ago

Well in bit operations it works, but when generated SQL, it creates also working but ineffective query.

You will never write StartDate > x & EndDate < y and StartDate > x && EndDate < y is correct one which is represented in expressions as AndAlso

NN--- commented 2 years ago

I see. So it is easily testable having some right side side-effect and validating it is not called when left side is truthy.

NN--- commented 2 years ago

@sdanyliv Adding test for this would take more time than I have now. If you have time for a unit test, it will be greatly appreciated. Pushed the fix.

sdanyliv commented 2 years ago

No time, otherwise I'll just propose PR. I've seen this bug accidentally when analysed generated expression tree.