I have a problem with a project. Iâ€™m trying to get a list of companies, but only filter those companies that are located in â€œStockholmâ€.
**Company**: CompanyID CompanyName etcâ€¦ **CompanyAddressDetails** (relation table): Company_CompanyID CorrespondingAddress_AddressID **CorrespondingAddress**: AddressID StreetName City etcâ€¦
Now what I first do is a query:
var companyModel = from c in db.Company select c;
Which gets the full list of companies and having their Corresponding Addresses (which can be multiple), so the results looks like this:
So my question is: how can I filter depending on what one of the nestled elements under CorrespondingAddress is? City for example?
So far I tried
companyModel = companyModel.Where(s => s.CorrespondingAddress.Where(x => x.City.Equals("Stockholm"))); companyModel = companyModel.Where(s => s.CorrespondingAddress.ToList().First().Address.Equals("Stockholm"));
But none of them works. Thanks!
companyModel = companyModel .Where(s => s.CorrespondingAddress .Any(x => x.City.Equals("Stockholm")));
companyModel = companyModel.Where(s => s.CorrespondingAddress.Any(x => x.City.Equals("Stockholm")));