Nested filter on Data Transfer Object using OData Wep Api

前端 未结 1 1328
無奈伤痛
無奈伤痛 2020-12-14 02:13

I have a wep api project consumes data using odata but I\'m having some problems with odata wep api.

when I execute that query

/api/values?$to

1条回答
  •  感情败类
    2020-12-14 02:43

    As the exception message tells you, the query that you have is invalid.

    /api/values?$top=50&$filter=Comments/Fortuneteller/FullName eq 'some string'
    

    is equivalent to the linq expression

    fortuneDTOs.Where(f => f.Comments.Fortuneteller.FullName == "some string").Top(50)
    

    As you can see fortuneDTOs.Comments.Fortuneteller is incorrect as Comments is a collection and it doesn't have a property named 'FullName'.

    You should use Any/All to filter on collections. For example, if you are trying to find all the fortunes where one of the commentators is 'some string', you can do

    /api/values?$top=50&$filter=Comments/any(c: c/Fortuneteller/FullName eq 'some string')
    

    If instead you want to find out all the fortunes where all the comments are made by only one commentator 'some string', you can do

    /api/values?$top=50&$filter=Comments/all(c: c/Fortuneteller/FullName eq 'some string')
    

    0 讨论(0)
提交回复
热议问题