Question

I have created an ODATA webAPI in ASP.NET MVC 5.0, where I am getting data in below format:

    <ArrayOfVMUser xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FX_OSS.ViewModels">
    <VMUser>
    <address>addsadfsadfasdfsadfsadfsdf</address>
    <emailAddress>amitendra.srivastava@espire.com</emailAddress>
    <employeeID>110786</employeeID>
    <firstName>Amitendra</firstName>
    <flag i:nil="true"/>
    <handPhone>11111</handPhone>
    <isActive>true</isActive>
    <landlineNo>11111</landlineNo>
    <lastName>Srivastavasa</lastName>
    <loginID>amitendra.srivastava</loginID>
    <modifiedBy>Amitendra.srivastava</modifiedBy>
    <modifiedDate>2014-04-04T00:00:00</modifiedDate>
    <roleName i:nil="true"/>
    <userGroup i:nil="true"/>
    <userGroups>...</userGroups>
    <userRoles>
    <VMUserRole>
    <LoginID>amitendra.srivastava</LoginID>
    <ModifiedBy i:nil="true"/>
    <ModifiedDate i:nil="true"/>
    <RoleName>Installer</RoleName>
    </VMUserRole>
<VMUserRole>
    <LoginID>amitendra.srivastava</LoginID>
    <ModifiedBy i:nil="true"/>
    <ModifiedDate i:nil="true"/>
    <RoleName>Specialist</RoleName>
    </VMUserRole>
    </userRoles>
    <zoneCode>North</zoneCode>
    </VMUser>

How can I write a URI filter to get list of user whose rolename is 'specialist'

Something like

/api/UsersSvc?$filter=userRoles.VMUserRole.RoleName eq 'Specialist'

Was it helpful?

Solution 2

Finally from Daniel post I realized that I need to use Any | All filter on collection. and below URL worked for me. Thanks Daniel!!

http://localhost:4444/api/userssvc?$filter=userRoles/any(c: c/RoleName eq 'specialist')

OTHER TIPS

This should be possible by using / instead of .

/api/UserSvc?$filter=userRoles/VMUserRole/RoleName eq 'Specialist'

But keep in mind that this is only working for 1-1 or n-1 relations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top