开发者

Lambda expression Where on navigation property

开发者 https://www.devze.com 2022-12-14 07:16 出处:网络
Good afternoon, I have three entities (that concern this question) Company (ID, etc..) CompanyAddress (AddressID, CompanyID, Rank)

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 detail开发者_JS百科s 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


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>.

0

精彩评论

暂无评论...
验证码 换一张
取 消