Set multiple columns in LINQ Join on syntax

ramco1917
 
on Jul 04, 2022 11:13 PM
282 Views

Hi

How to Join on multiple columns in Linq, In addition to BookId i want join also on StudentId.

public List<View_SessionDeliveryCalendarDetails_Student> GetOrderingInput()
{
    List<View_SessionDeliveryCalendarDetails_Student> Result = (from t in context.View_SessionDeliveryCalendarDetails_Students
                                                                join t2 in context.View_BookDeliveryDetails
                                                                on t.BookID equals t2.BookID 
                                                                orderby t.Name
                                                                select t).ToList();
    return Result;
}

Thanks

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 04, 2022 11:18 PM
on Jul 04, 2022 11:22 PM

Hi ramco1917,

You have to use an anonymous type.

public List<View_SessionDeliveryCalendarDetails_Student> GetOrderingInput()
{
    List<View_SessionDeliveryCalendarDetails_Student> Result = (from t in context.View_SessionDeliveryCalendarDetails_Students
                                                                join t2 in context.View_BookDeliveryDetails
                                                                on new { t.BookID, t.StudentId } equals new { t2.BookID, t2.StudentId }
                                                                orderby t.Name
                                                                select t).ToList();
    return Result;
}