2012 m. rugpjūčio 4 d., šeštadienis

LINQ: join inner, join outer

inner join:

full outer join:



 Pagal: http://stackoverflow.com/questions/38549/sql-difference-between-inner-and-outer-join



Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click


Dim oTrain = From t In oDB.TrainingSelfs



Join c In oDB.TrainingCourses On c.CourseID Equals t.TrCourseID



Join cdesc In oDB.TrainingDescs On cdesc.TrDID Equals t.TrDescID



Group Join em In oDB.Employees On em.Id Equals t.TrRecBy Into tbtmp = Group



From em In tbtmp.DefaultIfEmpty


If lstSite.SelectedValue <> "" Then oTrain = oTrain.Where(Function(x) x.t.TrSite = lstSite.SelectedValue)


If lstTrainee.SelectedValue <> "" Then oTrain = oTrain.Where(Function(x) x.t.TrainingEmployeeSelfs.Any(Function(es) es.TrEmpID = lstTrainee.SelectedValue))


If lstTrainer.SelectedValue <> "" Then oTrain = oTrain.Where(Function(x) x.t.TrTrainerID = CInt(lstTrainer.SelectedValue))


If lstTrainerEnter.SelectedValue <> "" Then oTrain = oTrain.Where(Function(x) x.t.TrRecBy = CInt(lstTrainerEnter.SelectedValue))



Dim qResult = From x In oTrain Order By x.t.TrDate Descending



Select New TrainSlfView With {

 .TrID = x.t.TrID,

 .TrDate = x.t.TrDate,

 .TrTrainerName =


If(x.t.TrTrainerID IsNot Nothing, If(oUser.ISEmpSite = "Lithuania", x.t.TrTrainerIDEmployee.NameLast & " " & x.t.TrTrainerIDEmployee.NameFirst, x.t.TrTrainerIDEmployee.NameFirst & " " & x.t.TrTrainerIDEmployee.NameLast), x.t.TrTrainerName),

 .TrDuration = x.t.TrDuration,

 .TrCost = x.t.TrCost,

 .TrLocation = x.t.TrLocation,

 .TrTitle = x.cdesc.TrDTitle,

 .TrCourseTitle = x.c.CourseTitle,

 .TrStatus = x.t.TrStatus,

 .TrNotes = x.t.TrNotes

 }


 grdTrainingView.DataSource = qResult

 grdTrainingView.DataBind()



End Sub

Komentarų nėra:

Rašyti komentarą