Pages

Tuesday 19 August 2014

Inner join in linq

Inner Join in linq:

Following code shows the inner join using Linq to Entities. Linq query : var result=(from s in db.schedules join sp in db.programs on s.scheduleId equals sp.scheduleId join pm in db.programme_data on sp.ProgramId equals pm.ProgramId where (s.date >= '1 aug 2014') orderby s.date, sp.starttime select new { s.date, sp.starttime,pm.pgm_name}); Code Explanation : In above code I performed the inner join operation on three entities named schedules, programs and programme_data. Here I performed first join operation in between schedules and programs entities on the field scheduleId i.e. primary key in the table schedules and foreign key in second table i.e. programs. Then on I performed join opertion with third table i.e. programme_data on the field on the field ProgramId i.e. primary key in the table schedules and foreign key in second table.

No comments:

Post a Comment