Join three tables with Entity Framework
Solution 1:
You have navigation properties in your model. That means you don't need to worry about joins - they will be generated for you.
The equivalent LINQ query is simple as that:
var query = from hasta in db.Hasta
select new
{
hasta.HastaAdSoyad,
hasta.Randevu.RandevuTarihi,
hasta.Randevu.RandevuSaati
};
var result = query.ToList();
It's not clear why the original SQL query includes join to Doktor
table.
If you really want joins (for some unknown reason), then the query is
var query = from hasta in db.Hasta
join randevu in db.Randevu on hasta.RandevuId equals randevu.RandevuId
join doktor in db.Doktor on randevu.DoktorId equals doktor.DoktorId
select new
{
hasta.HastaAdSoyad,
randevu.RandevuTarihi,
randevu.RandevuSaati
};