score:4
i believe example section from how to: perform left outer joins msdn page is really well explained. let's project it to your example. to quote first paragraph from the page
the first step in producing a left outer join of two collections is to perform an inner join by using a group join. (see how to: perform inner joins (c# programming guide) for an explanation of this process.) in this example, the list of person objects is inner-joined to the list of pet objects based on a person object that matches pet.owner.
so in your case, the first step is to perform an inner join of list of students
objects with the list of marks
objects based on markid
in students
object matches markid
in marks
object. as can be seen in the quote, inner join is being performed using group join. if you check note
section in msdn page on how to perform group join, you can see that
each element of the first collection appears in the result set of a group join regardless of whether correlated elements are found in the second collection. in the case where no correlated elements are found, the sequence of correlated elements for that element is empty. the result selector therefore has access to every element of the first collection.
what this means in the context of your example, is that by using into
you have group joined
results where you have all students
objects, and sequence of correlated elements of marks
objects (in case there is no matching marks
objects, the sequence is going to be empty).
now let's go back to how to: perform left outer joins msdn page
, in particular second paragraph
the second step is to include each element of the first (left) collection in the result set even if that element has no matches in the right collection. this is accomplished by calling defaultifempty on each sequence of matching elements from the group join. in this example, defaultifempty is called on each sequence of matching pet objects. the method returns a collection that contains a single, default value if the sequence of matching pet objects is empty for any person object, thereby ensuring that each person object is represented in the result collection.
again, to project this to your example, defaultisempty()
is being called on each sequence of matching marks
objects. as explained above, the method returns a collection that contains a single, default value if the sequence of matching marks
objects is empty for any student
object, which ensures each student
object will be represented in the resulting collection. as a result what you have is set of elements, that contain all student
objects, and matching marks
object, or if there is no matching marks
object, default value of marks
, which in this case is null
.
score:1
what i can say is that "into marksgroup" stores the result data of your joined tables into a temporary (application based, not database based) resultset (in sql terms: a table, so its a select into
)
in the next line, your code then selects from marksgroup the columns with your data (in sql terms: select student, department, software, status, marked from marksgroup
so basically, it's getting your data from the db, then putting it aside to "marksgroup, and in the very next step getting marksgroup back in your fingers to take out the data you want to use in your c# code.
try to get rid of marksgroup, it should be possible (haven't tested ist with your code). it should be something like this:
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
select new
{
student = st.studentname,
department = p.departmentname,
software = sv.softwareversionname,
status = st.statusname,
marked = m != null ? m.markname : "-- not marked --"
};
your second question with 'm' : this should also show a different behaviour without your temporary resultset "marksgroup"
Source: stackoverflow.com
Related Query
- Left outer join using LINQ -- understanding the code
- Using multiple LINQ statements with into , for the DefaultIfEmpty() of the left outer join not working
- trying to get the left outer join with linq expresssion using multiple tables in C#
- How do you perform a left outer join using linq extension methods
- Extension method for IQueryable left outer join using LINQ
- LINQ left outer join query error: OuterApply did not have the appropriate keys
- How to do a left outer join in Entity Framework without using the query syntax?
- How can I implement a LEFT OUTER JOIN in LINQ using lambda syntax on Entity Framework Core 2.0?
- How can I code an outer join using LINQ and EF6?
- How to write a LEFT OUTER JOIN where the right side is null in LINQ to SQL?
- Left outer join null using VB.NET and LINQ
- Linq left outer join not working using DefaultIfEmpty
- Left outer join using LINQ Query Syntax EF Core C#
- Multiple outer join using Linq with 2 joins to the same table/object. Got the SQL, need the Linq to Entity
- Using Left Outer Join in Linq
- Need Left Outer Join in LINQ using Extension Method /Query Syntax
- LINQ join query with multiple fields using left outer join
- LEFT OUTER JOIN on two Dictionary<int, string> using LINQ
- Left Join on Linq query when also using the Where clause on joint table
- Name doesn't exist in the current context LEFT OUTER JOIN in LINQ
- Using LINQ to perform a left outer join
- Left Join in Linq and using the variable for other joins
- Null value in the result of a left outer join linq causes error
- LINQ Left Outer Join only the first record
- Joining 3 tables and using a left outer join with linq in EF Core 3.1.1
- Performing 1-to-1 Left Outer Join in LINQ using Lambda expression
- Left outer join off of group by dataset using linq
- Left Join using Linq with Lambda Expressions returning the Left table
- How do you perform a left outer join with a where clause using linq lambda extension methods
- LINQ Updating the selected object while doing a left outer join
More Query from same tag
- Is it really this hard to just do a LEFT JOIN?
- Why is LINQ .Where(predicate).First() faster than .First(predicate)?
- LINQ - How do I compare the first two items in a group then the next?
- Linq to SQL Extended Data Classes - Share a DataContext
- LINQ not producing expected results
- Why: LINQ to Entities does not recognize the method?
- C# NET LINQ to Entities does not recognize the method
- Converting Oracle SQL query with left outer join to Linq
- Compare date if there is a date in the database
- Using built-in sql functions in a LINQ query?
- Can I filter this delegate to check if any name is repeated and remove
- Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Collections.Generic.IList'
- search list in where with and condition
- Identify methodinfo that has HTTPPost() attribute
- how to join multiple tables in linq using flag field
- Execute Stored Procedure with XMl datatype in Entity model
- Linq List<string> union
- linq weekly grouping?
- Show searched value in exception when nothing is found with First()
- How do you buffer items into groups in Reactive Extensions?
- Change in value based on criteria with LINQ
- Create a one to many collection from linq result setC#
- Dynamically create properties in anonymous type
- Getting List of Routes from RouteCollectionRoute
- Transpose a List<T> using c#
- Returning a custom list class type from LINQ Query - return same type going in that is coming out
- VB.NET error using linq
- How to convert IQueryable to EntityCollection
- How to return multiple rows using LINQ lambda expression from SQL Server 2014?
- how to Order a CollectionA using ListB ordering it in order of ListB Items in VB.net