In this case, we can group the combination of both visit and device like below so that we get repeated device for the same visit.

from s in db.Services.Where(condition)
where s.Active && (hasSupportGeneralAccess ||  s.Visit.Site.Branch.Users.Any(u => u.Id == userId)) && s.Device != null orderby s.Visit.Start descending
group s by (s.Visit + "." + s.Device) into newgroup
select newgroup.FirstOrDefault();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top