How to use left join in Entity Framework

Before going to the topic let see what is Left join.A Left outer join is a join in which each element of the first collection is returned, regardless of whether it has any correlated elements in the second collection. It can be performed by calling the DefaultIfEmpty() method on the results of a group join. Below is the example

 var result= (from st in db.StudentMaster
                  join cos in db.CourseMaster on st.CourseId equals cos.CourseId into     studentdet
                  from stu in  studentdet.DefaultIfEmpty()
                  select new { st.StudentName,cos.CourseName} )

Below is the same code for the SQL query.

Select st.StudentName, cos.CourseName from StudentMaster st left join CourseMaster cos on st.CourseId = cos.CourseId.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button