public decimal LoadedTerminalAmount(IUnitOfWork uow, int routelistId, int terminalId) { CarLoadDocument carLoadDocumentAlias = null; CarLoadDocumentItem carLoadDocumentItemAlias = null; var query = uow.Session.QueryOver(() => carLoadDocumentAlias) .JoinAlias(c => c.Items, () => carLoadDocumentItemAlias) .Where(() => carLoadDocumentAlias.RouteList.Id == routelistId) .And(() => carLoadDocumentItemAlias.Nomenclature.Id == terminalId) .Select(Projections.Sum(() => carLoadDocumentItemAlias.Amount)) .SingleOrDefault <decimal>() + _routeListRepository.TerminalTransferedCountToRouteList(uow, uow.GetById <RouteList>(routelistId)); return(query); }