Hell Team,
Please I have three tables am trying to join in my mvc controller, and am able to call the data from order table and orderDetail table but item is not pulling from the item table, kindly assist please.
public ActionResult GetAllCashierReport(string sDate = null, string eDate = null) { DateTime? startDate = null; if (!string.IsNullOrEmpty(sDate)) startDate = Convert.ToDateTime(sDate); DateTime? endDate = null; if (!string.IsNullOrEmpty(eDate)) endDate = Convert.ToDateTime(eDate); var dataList = objRestaurantDBEntities.tblOrders.Join( objRestaurantDBEntities.tblOrderDetails, order => order.OderId, orderdetail => orderdetail.OderId, (order, orderdetail) => new {order = order, orderDetail = orderdetail }); var modifiedData = dataList.GroupBy(x => new { x.order.OrderDate, x.orderDetail.ItemId }).Select(x => new OrderDetail { OrderDetailId = x.FirstOrDefault().orderDetail.OrderDetailId, OderId = x.FirstOrDefault().order.OderId, strOrderDate = x.Key.OrderDate, ItemId = x.FirstOrDefault().orderDetail.ItemId, ItemName = x.FirstOrDefault().orderDetail.tblItem.ItemName, UnitPrice = x.FirstOrDefault().orderDetail.UnitPrice, Quantity = x.Sum(s => s.orderDetail.Quantity), Discount = x.Sum(s => s.orderDetail.Discount), Total = x.Sum(s => s.orderDetail.Total) }).ToList(); modifiedData.ForEach(a => { a.OrderDate = Convert.ToDateTime(a.strOrderDate); }); if (startDate != null) { modifiedData = modifiedData.Where(a => a.OrderDate >= startDate).ToList(); } if (endDate != null) { modifiedData = modifiedData.Where(a => a.OrderDate <= endDate).ToList(); } var responseData = modifiedData.OrderBy(a => a.OrderDate).ToList(); return Json(modifiedData, JsonRequestBehavior.AllowGet); }