Search code examples
entity-relationshipodatarelationships

how to get referencial data using odata


I have two tables, NetworkAccount and Division. The are related by DivisionID NetworkAccount has the full user information including a DivisionID Division has all related information related to a division.

I have the users logon name, how can I retrive his DivisionName which is stored in the Division table. I want to do this with one query to the oData service.

I've tried the following and nothing is giving me the answer I wanted.

http://localhost:54471/NetworkInfo.svc/Divisions?$filter=Username eq 'test\name'

I get the following

<message xml:lang="en-CA">No property 'Username' exists in type 'NetworkInfoService.Division' at position 0.</message>

http://localhost:54471/NetworkInfo.svc/Divisions?$filter=NetworkAccount/Username eq 'test\name' I get the following

<message xml:lang="en-CA">No property 'NetworkAccount' exists in type 'NetworkInfoService.Division' at position 0.</message>

But if I do the opposite, if I want to get users that belong to a certain division, it works no problem, see below.

localhost:54471/NetworkInfo.svc/NetworkAccounts?$filter=Division/Name eq 'SomeName'

Any help would be much appreciated. Thanks


Solution

  • Ok, I figured out the syntax... it goes like this:

    http://localhost:12345/NetworkInfo.svc/NetworkAccounts?$filter=Username eq 'test\name'&$expand=Division
    

    The $expand keyword is the trick.