jmease
jmease

Reputation: 2535

Filter Generic Collection Down to Records Containing Any Item in Collection of String

string rep = "Joe Shmoe"

ObjectSet<StoreData> storeData = edmContext.StoreData;
ObjectSet<CallData> callData = edmContext.CallData;
IEnumerable<string> repStoreData = storeData.Where(r => r.RepName == rep).Select(s => s.Location);

IEnumerable<CallData> repCallData = Here is where I want to filter down the callData collection down to just the records that have a location that is contained in the repStoreData collection

I've tried using some form of Join and Any but don't really understand the arguments those are asking for.

This was my best attempt and it is a no go.

... = callData.Join(d => d.LOCATION.Any(repStoreData));

Upvotes: 0

Views: 141

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499790

Well you don't have to use a join. You could just use:

callData.Where(d => repStoreData.Contains(d.LOCATION))

That's assuming d.LOCATION is a single string.

However, you probably don't want to do that with your current declaration of repStoreData as IEnumerable<string> - LINQ won't be able to turn that into a query to be executed at the database.

If you're able to declare repStoreData as IQueryable<string>, however, that would be more likely to work well. I don't know whether that will work with ObjectSet<T>, but I'd hope so.

Upvotes: 2

Related Questions