-1

I have 2 Tables AtdDailyAttendance and AcdAdmissionSessionDetails. I want to join these 2 tables from linq based on 2 ids, which means in Sql this join looks like

SELECT a.Id, a.DateId,  
    a.StudentLedgerId, a.AttendanceTypeId,   
    a.SchoolId, a.UserId, a.SessionId, 
    d.ClassId,d.MediumId,    
    d.StreamId, d.ShiftId,  
    d.SectionId   
FROM AtdDailyAttendance a INNER JOIN  AcdAdmissionSessionDetail d
    ON a.StudentLedgerId = d.StudentLedgerId AND  a.SessionId = d.SessionId

But in LINQ I'm unable to do this. I tried this way

var query =
    from a in dbCOntext.AtdDailyAttendances
    join b in dbCOntext.AcdAdmissionSessionDetails
    on a.StudentLedgerId equals b.StudentLedgerId
    // on a.SessionId equlas b.SessionId
    select new
    {
        a.AtdSetedDatesForAttendance,
        a.DateId,
        a.StudentLedgerId,
        a.SchoolId,
        a.UserId,
        a.SessionId,
        b.ClassId,
        b.SectionId,
        b.MediumId,
        b.StreamId
    }

var liResult = query.ToList();

Here I'm unable to perform join between SessionId.

Amit Bisht
  • 4,870
  • 14
  • 54
  • 83

2 Answers2

2

I think you're looking for:

var liResult = (from a in dbCOntext.AtdDailyAttendances
  join b in dbCOntext.AcdAdmissionSessionDetails
  on new { a.StudentLedgerId, a.SessionId } 
     equals new { b.StudentLedgerId, b.SessionId}
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
-1

See if this will work:

 dbContext.AtdDailyAttendances.Join(dbContext.AcAdmissionSessionDetails, m => m.StudentLedgerId,      n => n.StudentLedgerId, (m, n) => new{ 
                                m.AcdAdmissionSessionDetails,
                                m.DateId,
                                m.StudentLedgerId,
                                m.SchoolId,
                                m.UserId,
                                AttendanceSessionId = n.SessionId,
                                AdmissionSessionId = m.SessionId,
                                n.ClassId,
                                n.SectionId,
                                n.MediumId,
                                n.StreamId

  }).Where(n => n.AttendanceSessionId == n.AdmissionSessionId).ToList();
Rickey
  • 7,830
  • 1
  • 19
  • 12