views:

101

answers:

1

Good afternoon,

I have three entities (that concern this question)

Company (ID, etc..) CompanyAddress (AddressID, CompanyID, Rank) AddressDetails (AddressID, Street, City, State, Zip)

The reason Rank and company id aren't in the AddressDetails is because the address detas are shared with contacts via a ContactAddress entity.

Anyway, I need to build an IQueryable given an IQueryable that will check if a string is contained in the City (and eventually or state). I'd like to use Lambda expressions not the from c in companies syntax...I tried

query = query.Select(c => c.Addresses.Where(a => a.AddressDetails.City.Contains(City)).Select(ca => ca.Company));

In this example c.Addresses is the navigation property for CompanyAddress.

Thanks for any help,

Paul

+1  A: 

I think that this will work:

query = query.Where(c => c.Addresses.Any(a => a.AddressDetails.City.Contains(City)));

I assume that query is IQueryable<Company>.

LukLed
Thanks...I need to get to know the Any extension method a bit better...It didn't even occur to me.
Paul
`Any` is something like `exists` in sql.
LukLed