Closed DolgsthrasirCGN closed 4 years ago
Hi, the current version unfortunately loses the brackets. I will try to do something
Hi. I can suggest for the time being such an option to support brackets.
.Filter((s, f, o) => s.IdRule == constValue
&& s.IsActive
&& (f.Date(s.EndDate.Value) == default(DateTimeOffset?) || s.EndDate > DateTime.Today)
&& (f.Date((DateTimeOffset)s.BeginDate) != default(DateTime?) || f.Date((DateTime)s.BeginDate) <= DateTime.Now)
&& o.In(s.ODataKind.ODataCode.Code, constStrIds))
$filter=(((((IdRule eq 3) and IsActive) and ((date(EndDate) eq null) or (EndDate gt 2020-08-26T00:00:00Z))) and ((date(BeginDate) ne null) or (date(BeginDate) le 2020-08-26T16:29:36Z))) and ODataKind/ODataCode/Code in ('123','512'))
The main problem is that the parentheses are created automatically if this is a combined expression, and it is not easy to determine those that were added manually. In the future, I will be working on removing the automatically added parentheses from the uri.
Removed unnecessary parentheses and added optional controls
.Filter((s, f, o) => s.IdRule == constValue
&& s.IsActive
&& (f.Date(s.EndDate.Value) == default(DateTimeOffset?) || s.EndDate > DateTime.Today)
&& (f.Date((DateTimeOffset)s.BeginDate) != default(DateTime?) || f.Date((DateTime)s.BeginDate) <= DateTime.Now)
&& o.In(s.ODataKind.ODataCode.Code, constStrIds), useParenthesis: true)
$filter=(((IdRule eq 3 and IsActive) and (date(EndDate) eq null or EndDate gt 2020-08-29T00:00:00Z)) and (date(BeginDate) ne null or date(BeginDate) le 2020-08-29T18:09:15Z)) and ODataKind/ODataCode/Code in ('123','512')
Generates following odata query.
$filter=IdRule eq 3 and IsActive and date(EndDate) eq null or EndDate gt {DateTime.Today.ToString("O")} and date(BeginDate) ne null or date(BeginDate) le {DateTime.Today.ToString("yyyy-MM-dd")} and ODataKind/ODataCode/Code in ('123','512')
All the bracketing of the lambda is not taken into account. It should be
$filter=IdRule eq 3 and IsActive and (date(EndDate) eq null or EndDate gt {DateTime.Today.ToString("O")}) and (date(BeginDate) ne null or date(BeginDate) le {DateTime.Today.ToString("yyyy-MM-dd")}) and ODataKind/ODataCode/Code in ('123','512')