0
如何爲此問題編寫where子句?複雜的LINQ與實體框架查詢
我想獲得各自的員工在當天有時間做特定服務的業務列表。
例如: 有人搜索週四下午3點提供服務x的企業。它需要檢查每個員工的可用性,預訂和需要多長時間完成服務(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;
}
請顯示/使用導航屬性代替聯接 –
那麼到目前爲止您嘗試過什麼? – DotNetHitMan