I've just started using Linq and managed to get the records I needed using the code below. I have several criteria that are applied if Ids are selected by the user. This appraoch works well and is easy to maintain.
However...I now need to add further criteria based on records in a related table. I can't seem to find the syntax on how to do this after several hours searching.
The tables are related in the dbml. The records in the child table have a couple of Ids (on further lookup tables) that I need to also filter by.
E.g. Record in MyTable has two child records, I want to check if either of these records have an Id from a list of integers.
Thanks for any help..
Dim myRecs As IQueryable = m_db.MyTable
If myCriteria1Ids.Count > 0 Then
myRecs = myRecs.Where(Function(n) m_myCriteria1Ids.Contains(CInt(n.CriteriaId1)))
If myCriteria2Ids.Count > 0 Then
myRecs = myRecs.Where(Function(n) m_myCriteria2Ids.Contains(CInt(n.CriteriaId2)))
'several more criteria added using same process
Dim output = (From p In myRecs _
Order By p.MyId Ascending _