odata.net
odata.net copied to clipboard
Combining filtering using expression and query options
Combining filtering using expression and query options produces an invalid OData query.
Assemblies affected
Microsoft.OData.Client 7.12.0
Reproduce steps
class TestObj
{
[Key]
public int Id { get; set; }
public string Value1 { get; set; }
public int Value2 { get; set; }
}
DataServiceContext context = new() {BaseUri = new("http://localhost")};
DataServiceQuery<TestObj> query = context.CreateQuery<TestObj>("TestObjs");
query = (DataServiceQuery<TestObj>)query.Where(o => o.Value1 == "xxx");
query = query.AddQueryOption("filter", "Value2 eq 123");
Expected result
http://localhost/TestObjs?$filter=Value1 eq 'xxx' and Value2 eq 123
Actual result
http://localhost/TestObjs?$filter=Value1 eq 'xxx'&filter=Value2 eq 123
I'd prefer to '$filter=Value1 eq 'xxx' and Value2 eq 123'. If that's the case, it's a bug at OData client side.
Maybe it's better to throw an exception when calling "AddQueryOption" and see we have $filter already?
I don't quite understand your answer. It's not a question of preference. The query string in "Actual result" is invalid.
Any news on this?
Ping @xuzhg
Any news on this?
Sorry, I am not following up on this issue. @KenitoInc any news for @Robelind
Ping @KenitoInc
This is a bug. @asanyaga can this be added to the backlog?