odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

Combining filtering using expression and query options

Open Robelind opened this issue 2 years ago • 3 comments

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

Robelind avatar Aug 02 '22 09:08 Robelind

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?

xuzhg avatar Aug 02 '22 15:08 xuzhg

I don't quite understand your answer. It's not a question of preference. The query string in "Actual result" is invalid.

Robelind avatar Aug 03 '22 10:08 Robelind

Any news on this?

Robelind avatar Sep 27 '22 10:09 Robelind

Ping @xuzhg

Robelind avatar Oct 26 '22 07:10 Robelind

Any news on this?

Sorry, I am not following up on this issue. @KenitoInc any news for @Robelind

xuzhg avatar Oct 26 '22 16:10 xuzhg

Ping @KenitoInc

Robelind avatar Feb 14 '23 15:02 Robelind

This is a bug. @asanyaga can this be added to the backlog?

KenitoInc avatar Feb 14 '23 15:02 KenitoInc