This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi I've had to change one of my model relationships from one-to-many to a through association. Now I'm not sure how to change a query I was using to handle that new association type. Employees could previously only have one region, now they can have multiple. A "job" has just one region. In the examples below "theJob" is already an instantiated entity. The query I had was: var matchingEmployees = localUOW.Employees.Where(emp => emp.IndustriesId == theJob.IndustryId && emp.RegionId == theJob.RegionId); Now I need to change it to something like: var matchingEmployees = localUOW.Employees.Where(emp => emp.IndustriesId == theJob.IndustryId && emp.EmployeeRegions.Select(empRegion => empRegion.RegionId).Contains(theJob.RegionId)); But I get a "The method 'Select' is not supported" error on the latter. What should that query look like now? Thanks a lot! |
|
|
You will want to use:
Another way of writing this which is a bit more readable is by using the Query syntax rather than LINQ where you can say:
|
|
|
Cool, thanks very much - works perfectly. |
|