I have these tables: components, devicehardwareprofiles, componenttemplates, cashrecyclercounters
on MsSql database
I need to fill this variables: int capacity, loaded
by data from this query:
select sum(ct.capacity * cc.denomination) as capacity, sum(cc.loaded * cc.denomination) as loaded
from components c
left outer join devicehardwareprofiles dhp
on dhp.deviceid = c.deviceid
left outer join componenttemplates ct
on ct.hardwareprofileid = dhp.hardwareprofileid and ct.typecode = c.typecode and ct.position = 1
left outer join cashrecyclercounters cc
on cc.componentid = c.componentid
where c.deviceid = 72 and c.typecode = 155 and cc.currency = 810
How to convert this SQL to nHibernate QueryOver expression and get required data?
Addition: DTO and mappings are here: https://github.com/elscript/CashMaster
Typecode 155 stands for CashRecyclerHopper
I've already tried this one expression:
CashRecyclerHopper component = null;
DeviceHardwareProfile profile = null;
ComponentTemplate template = null;
var query = _cmSession.QueryOver(() => profile)
.JoinQueryOver(x => x)
.JoinAlias(a => a.HardwareProfileId, () => template, JoinType.LeftOuterJoin)
.JoinAlias(b => b.DeviceId == component.ParentDevice.DeviceId, () => component, JoinType.LeftOuterJoin)
.JoinAlias(c => c.HardwareProfileId == template.HardwareProfileId, () => template, JoinType.LeftOuterJoin);
But it gave me the exception:
Could not determine member from (b.DeviceId == value(CashMasterWeb.Controllers.OptimizationController+<>c__DisplayClass2).component.ParentDevice.DeviceId)
Exception Details: System.Exception: Could not determine member from (b.DeviceId == value(CashMasterWeb.Controllers.OptimizationController+<>c__DisplayClass2).component.ParentDevice.DeviceId)
Source Error:
Line 81: ComponentTemplate template = null; Line 82: Line 83: var query = _cmSession.QueryOver(() => profile) Line 84: .JoinQueryOver(x => x) Line 85: .JoinAlias(a => a.HardwareProfileId, () => template, JoinType.LeftOuterJoin)