2

I have the following model class method:-

public IQueryable<TMSSwitch> AllFindServer_Switches(int id        {



return tms.TMSSwitches.Where(c => c.TMSSwitchPorts.Any(a6=>a6.TechnologyID == id))

.Include(a10 => a10.TMSSwitchPorts.Where(a=>a.TechnologyID==id).Select(a=>a.Technology))
.Include(a11 => a11.TMSServer.Technology)
;}

But I am unable to define .Where inside the .Include, as I need to only include certain records from the navigation property. But the above code will cause the following error on run-time:-

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation propertie

Can anyone advice, if there is a way to have .Where inside .include ? Thanks

John John
  • 2,118
  • 8
  • 40
  • 65
  • You have your condition already in your .Any, so why would any TMSSitchPorts be returned that have no link to selected TMSSwitches? What happens if you just use `.Include(a10 => a10.TMSSwitchPorts.Technology` ? – oerkelens Nov 19 '13 at 10:13
  • but .Any is different than .Where.all the TMSSwithcPort will have a link to the TMSSwithes. but the TMSSwitchPort navigation property can have other links to other switches . so what I am trying to do is to select only the TMSSWitchPorts realted to the Switch but at the same time not to include other links to other switches.. – John John Nov 19 '13 at 10:32
  • Yes, it is. But since your Any means yuo only select TMSSwitches that have relevant TMSSwitchPorts, why would any _irrelevant_ TMSSwitchPorts be included? What is the result without that .Where? Do you have any indication that you receive TMSSwitchPorts that are not linked to selected TMSSwitches ? – oerkelens Nov 19 '13 at 10:34
  • currently the retrieved SwitchPorts will have at least one link to the associated TMSSWith, but also the retrieved SWitchPorts navigation property can have other links to other TMSSSwitches...which I am trying to aovird. currently I am doing the filtering on the view by using :-var item2 in item.TMSSwitchPorts.Where(a=> a.TechnologyID == ViewBag.ID). but I need the filtering to be inside my model class – John John Nov 19 '13 at 10:37
  • 1
    Yups, i was missing something. You are right, you do get extra Swiches. I'll have to think about that one – oerkelens Nov 19 '13 at 10:39

0 Answers0