I would be grateful if someone could explain the meaning of the term into while using LINQ. In general, I am trying to understand how to make INNER JOIN, LEFT OUTER JOIN etc. in C#.
I have the main table Students that stores a few foreign ID keys which then are substituted by their names when running a query. The names are read from look up tables such as Marks, SoftwareVersions, Departments etc. All fields are required but MarkID. The query I tried to build in LINQ is this:
SELECT * FROM dbo.Students INNER JOIN dbo.Departments ON dbo.Students.DepartmentID=dbo.Departments.DepartmentID INNER JOIN dbo.SoftwareVersions ON dbo.Students.SoftwareVersionID=dbo.SoftwareVersions.SoftwareVersionID INNER JOIN dbo.Statuses ON dbo.Students.StatusID=dbo.Statuses.StatusID LEFT JOIN dbo.Marks ON dbo.Students.MarkID=dbo.Marks.MarkID WHERE dbo.Students.DepartmentID=17; I somehow managed to get the code below worked after reading plenty of articles and watching some videos but I don't feel like I have a complete understanding of the code. The bits that confuse me are in 5th line ending with into and then in the very next line beginning with from m .... I'm confused what into does and and what really happens in from m .... And this is the code in LINQ:
var result = from st in dbContext.Students where st.DepartmentID == 17 join d in dbContext.Departments on st.DepartmentID equals d.DepartmentID join sv in dbContext.SoftwareVersions on st.SoftwareVersionID equals sv.SoftwareVersionID join stat in dbContext.Statuses on st.StatusID equals stat.StatusID join m in dbContext.Marks on st.MarkID equals m.MarkID into marksGroup from m in marksGroup.DefaultIfEmpty() select new { student = st.StudentName, department = p.DepartmentName, software = sv.SoftwareVersionName, status = st.StatusName, marked = m != null ? m.MarkName : "-- Not marked --" };