I have these two lists, one a list of Venue Objects, one a list of BlockedVenues objects.
I need to filter each item in the listOfAllVenues so that it doesn't contain any venue that is blocked
IQueryable<Venue> listOfAllVenues = MyDB.Venues; IQueryable<BlockedVenue> listOfBlockedVenues = Mydb.BlockedVenue; //I need something to accomplish this please // var listOfAllVenues_WithoutBlocked_Venues = ( Select All venues from listOfAllVenues where listOfAllVenues.ID is NOT in listOfBlockedVenues.VenueID)
Please note that yes both list types are different, but listOfAllVenues has an int ID field, and listOfBlockedVenues has a VenueID int field, i need to use these two
Many Thanks
LINQ query syntax always ends with a Select or Group clause. The Select clause is used to shape the data. You can select the whole object as it is or only some properties of it. In the above example, we selected the each resulted string elements.
Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.
An IEnumerable<T>.
Try this:
var filtered = listOfAllVenues .Where(x=>!listOfBlockedVenues.Any(y=>y.VenueId == x.Id));
It will get all Venues where Id is not in blockedVenues list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With