如何为这个问题写where子句?
我想得到一个企业的名单,在这一天,各自的雇员有时间做一项特定的服务。
例如:有人在周四下午3点搜索提供服务的企业。它需要检查每个员工的可用性、预订以及完成服务(ServiceEmployee.minutes)所需的时间(即预订长度)。
到目前为止,这就是我所拥有的:
public List<SearchModel.Result> GetServices(SearchModel.Request model)
{
var geo = DataUtility.GetGeo(model.lat, model.lng);
var results = (from b in _db.Businesses
join ad in _db.Addresses on b.addressId equals ad.addressId
join e in _db.Employees on b.businessId equals e.businessId
join av in _db.Availabilities on e.employeeId equals av.employeeId
join se in _db.ServiceEmployees on e.employeeId equals se.employeeId
join s in _db.Services on se.serviceId equals s.serviceId
where s.serviceId.Equals(model.serviceId) //service required
&& av.day.Equals(model.date.DayOfWeek) //day of the week required
//how to write the below where clause??
//and has at least one slot of time available (no bookings) that will fit the service time length (minutes)
//and is not over the employee's shift (Availability.endAt)
//
&& ad.geo.Distance(geo) <= 15000 //15km
select new SearchModel.Result
{
businessId = b.businessId,
businessName = b.name,
serviceName = s.name,
price = se.price, //potentially incorrect
time = av.startAt //potentially incorrect
}).ToList();
return results;
}这是数据库结构:

发布于 2015-09-17 11:35:06
我在G+上发布了你的问题的“答案”,但我想我会把它粘贴在这里,以获得更多的报道和更好的格式化:
如果我正确地理解了您,您需要的主要信息是在"Availability“表中。您可以使用它作为起点,并通过进一步的联接来细化查询。起始(基本) SQL查询将类似于:
SELECT Availabity.EmployeeId FROM Availability
WHERE day = :Query.day AND (EndAt - StartAt) >= :Query.ServiceDuration其结果将是一份在特定时间具备可用性的所有员工的名单。然后,您可以细化结果,将其缩小到提供给定服务的员工,等等。
https://stackoverflow.com/questions/32585925
复制相似问题