The following code causes the error "This request contains links to elements defined in a different data context." My 2 data contexts are created using 2 nested blocks using the code that calls this method and displays its results on the screen. The methods that this method invokes use only the data context it uses; they do not create any of their own. I confirmed that they are fine by inserting an additional return statement right before the one described below, and I have no problems, which makes me think that the problem is the LINQ instruction on the return line ... What am I doing wrong?
public static IQueryable<tblSurveyor> GetPossibleSurveyorsForSurvey(SurveyDataContext surveyContext,
FINDataContext finContext, int surveyID)
{
IQueryable<tblSurveyor> currentSurveyors =
GetSurveyorsForSurvey(surveyContext, surveyID);
tblSurvey currentSurvey = GetSurvey(surveyContext, surveyID);
tblLocContact facility = GetFacility(finContext, currentSurvey.FacilityID);
IQueryable<tblSurvey> surveysInState = GetSurveysInState(surveyContext, finContext,
facility.State);
return from task in surveyContext.tblSurveyor_Tasks
from surveys in surveysInState
from cSurveyor in currentSurveyors
from surveyors in surveyContext.tblSurveyors
where surveyors.SurveyorID != cSurveyor.SurveyorID &&
surveys.SurveyID == task.SurveyID &&
task.SurveyorID == surveyors.SurveyorID
select surveyors;
}
, , IQueryable . , . , (, , ).
tblSurvey[] surveysInState = GetSurveysInState(surveyContext, finContext,
state).ToArray();
. .
public static IQueryable<tblSurvey> GetSurveysInState(SurveyDataContext surveyContext,
FINDataContext finContext, string state)
{
return from survey in surveyContext.tblSurveys
from facility in finContext.tblLocContacts
where survey.FacilityID == facility.LocationID && facility.State == state
select survey;
}