Filter on Expanded entities in OData
Asked Answered
A

3

3

How to apply filtering conditions on expanded entities in OData ?

Suppose I have master entity as home having fields

homeId, StateId, CountyID, Address

and sub entities state as

StateId, StateName

and county as

CountyID, CountyName

I need to get the home addresses and Ids with a filter condition with state name and county name. How should be the url?

Avernus answered 8/8, 2013 at 10:46 Comment(1)
Did you solve this problem? if so then plz let us know..Veridical
S
1

Using the $expand keyword OData query should be something like:

/home/?$filter=state/statename eq 'STATE' and county/countyname eq 'COUNTY'&$expand=state,county&$select=homeId, Address

Sural answered 8/8, 2013 at 16:8 Comment(1)
Am getting below error : 'No property 'state' exists in type 'HomeModel.home' at position 0.'Avernus
B
0

I suspect your home entity type doesn't actually have navigation properties on it. In OData, if you want to connect two entities, you would create a property whose type matches the entity you want to link to. These properties (i.e., properties whose type is an entity type) are called navigation properties. If you want home to have an associated state, your home type would have a property called "State" or something like that, and that property would be of type state. Think of object-oriented programming instead of join-able IDs you would use in a relational database.

Similarly, home should have a property with type county if you want to connect a home entity to a county entity. Once you have navigation properties called "state" and "county", eoghank's answer should work for you.

Bromine answered 3/2, 2014 at 19:17 Comment(0)
Q
0

I have the same issue and i use the relational schema that links the two entities but even so only primary keys of expanded entity can be filtered or selected. I don't know how to call a diferent field that's not a primary key. See the following question: Question

Quillen answered 27/2, 2014 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.