Click here to Skip to main content
15,867,885 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I have a database containing 2 tables:
- recruiters
- Addresses

These tables have a n:m relationship.

I connect with the database through an OData api.

I'm trying to get the addresses of a specific recruiter but can't get it to work.

What I've tried is:
C#
var addressesQuery = from a in _container.Addresses.Expand(a => a.Recruiters.Where(p => p.ID =- recruiter_ID))
select a


This gives a System.NotSupported exception.
Specific:
"The expression a => a.Persons. Where( p => (p.ID == xxxxxx)) is not a valid expression for navigation path. The only supported operations inside the lambda expression body are MeberAccess and TypeAs.
The expression must contain at least one MeberAccess and it cannot end with TypesAs"

I've tried many variants but always get the error.

Anyone tips or ideas?

Jeroen
Posted
Updated 4-Nov-14 4:14am
v4
Comments
Herman<T>.Instance 3-Nov-14 10:27am    
have you tried:
var addressesQuery = from a in _container.Addresses.Expand(a.Recruiters)
select a
Jeroen E 3-Nov-14 10:37am    
Yes, that works.

But it returns all the addresses, and I want specific addresses of one recruiter.
Herman<T>.Instance 3-Nov-14 10:53am    
then:
var addressesQuery = (from a in _container.Addresses.Expand(a.Recruiters).Where(...)).FirstOrDefault();
Maciej Los 3-Nov-14 12:12pm    
I don't know exact answer, but found interesting article. Have a look here: How to implement a many-to-many relationship using Linq to Sql ?[^]

1 solution

I figured it out after I came across this link http://stackoverflow.com/questions/2247051/how-to-use-selectmany-with-dataservicequery[^]

I turned the query around by first querying and filtering the recruiters and then the addresses.

The query ended up like this:

C#
var addressesQuerry = from r in _container.Recruiters
.Where(r => r.ID == recruiter_ID)
from a in r.Addresses
select a;


Thnaks for thinking with me.
 
Share this answer
 
Comments
Maciej Los 4-Nov-14 4:11am    
+5!
Do not forget to mark your answer as a solution (green button).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900