public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var query = from a in db.Locations from b in db.Events where b.Id == id && a.ID == b.LocationId join c in db.Monsters on b.MonsterId equals c.Id into C from m in C.DefaultIfEmpty() join i1 in db.Images on a.ImageId equals i1.ID into I1 from ia in I1.DefaultIfEmpty() join i2 in db.Images on m.ImageId equals i2.ID into I2 from im in I2.DefaultIfEmpty() select new DetailsEventViewModel { Event = b, Location = a, LocationImage = ia != null ? ia : null, Monster = m != null ? m : null, MonsterImage = im != null ? im : null }; var oneEvent = query.FirstOrDefault(); if (oneEvent == null) { return(HttpNotFound()); } return(View(oneEvent)); }