Is this the proper way to accomplish joining 3 (or more) tables with LINQ (to SQL)? Especially the select
portion. Am I on the right track to return a single record(row) of data that spans across the tables?
public static DataTable GetCurrentEmploymentQuestionnaire(Guid employmentQuestionnaireID)
{
var Questionnaire = from employmentQuestionnaire in context.tblEmploymentQuestionnaires
join prevocService in context.tblEmploymentPrevocServices on
employmentQuestionnaire.PrevocServicesID equals prevocService.EmploymentPrevocID
join jobDevelopmetService in context.tblEmploymentJobDevelopmetServices on
employmentQuestionnaire.JobDevelopmentServicesID equals
jobDevelopmetService.JobDevelopmentServicesID
where employmentQuestionnaire.EmploymentQuestionnaireID == employmentQuestionnaireID
select
new
{
EmploymentQuestionnaireID = employmentQuestionnaire.EmploymentQuestionnaireID,
PlanID = employmentQuestionnaire.PlanID,
HasCommunityJob = employmentQuestionnaire.CommunityJob,
HasPrevocServices = employmentQuestionnaire.PrevocServices,
HasJobDevelopmentServices = employmentQuestionnaire.JobDevelopmentServices,
WhoCreated = employmentQuestionnaire.InsertUser,
WhenCreated = employmentQuestionnaire.InsertDate,
WhoUpdated = employmentQuestionnaire.UpdateUser,
WhenUpdated = employmentQuestionnaire.UpdateDate,
AvgRatePay = prevocService.AvgRatePay,
AvgHoursWeek = prevocService.AvgHoursWeek,
PrevocGoal = prevocService.PrevocGoal,
SkillsTaught = prevocService.SkillsTaught,
SkillsLearned = prevocService.SkillsLearned,
AnticipatedTransitionPlan = prevocService.AnticipatedTransitionPlans,
AnticipatedEndDate = prevocService.AnticipatedEndDate,
TypeWorkDesired = jobDevelopmetService.TypeWorkDesired,
NeedEmpServices = jobDevelopmetService.NeedEmploymentServices,
IsDVRProvidingServices = jobDevelopmetService.DVRProvidingServices,
DVRCurrentReferralExists = jobDevelopmetService.DVRCurrentReferral
};
return Questionnaire.CopyLinqToDataTable();
}
Database structure is as follows -->
tblEmploymentQuestionnaire
EmploymentQuestionnaireID uniqueidentifier Unchecked
PlanID int Unchecked
CommunityJob bit Checked
PrevocServices bit Checked
PrevocServicesID uniqueidentifier Checked
InsertUser varchar(50) Checked
InsertDate datetime Checked
UpdateUser varchar(50) Checked
UpdateDate datetime Checked
JobDevelopmentServices bit Checked
JobDevelopmentServicesID uniqueidentifier Checked
tblEmploymentPrevocServices
EmploymentPrevocID uniqueidentifier Unchecked
AvgRatePay varchar(50) Checked
AvgHoursWeek varchar(50) Checked
SettingID int Checked
PrevocGoal varchar(500) Checked
SkillsTaught varchar(500) Checked
SkillsLearned varchar(500) Checked
AnticipatedTransitionPlans varchar(500) Checked
AnticipatedEndDate datetime Checked
RatioID int Checked
rowguid uniqueidentifier Unchecked
tblEmploymentJobDevelopmentService
JobDevelopmentServicesID uniqueidentifier Unchecked
TypeWorkDesired varchar(50) Checked
PreferredWorkHoursID int Checked
NeedEmploymentServices bit Checked
DVRProvidingServices bit Checked
DVRCurrentReferral bit Checked
CMOProvidingServices bit Checked
CMONotProvidingReason varchar(500) Checked
PaidCoachingHoursID int Checked
PlanSegregatedToIntegrated varchar(500) Checked
RoleResponseJobDeveloper varchar(500) Checked
RoleResponseMember varchar(500) Checked
RoleResponseWWCTeam varchar(500) Checked
PlanDVRToWWCFund varchar(500) Checked
DVRCurrentReferralStatusID int Checked
Sorry it ended up being so long. If you are still with me, thank you and bonus appreciation points if someone can point out in the comments how I could have shortened this while still asking my question. I would appreciate it for future reference.