通过QueryOver连接nHibernate中的多个表

时间:2015-08-13 09:12:36

标签: c# join nhibernate aggregate-functions multiple-tables

我在MsSql数据库上有这些表:components, devicehardwareprofiles, componenttemplates, cashrecyclercounters

我需要通过此查询中的数据填充此变量:int capacity, loaded

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

如何将此SQL转换为nHibernate QueryOver表达式并获取所需数据?

增加: DTO和映射在这里:https://github.com/elscript/CashMaster

Typecode 155代表CashRecyclerHopper

我已经尝试过这一个表达式:

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);

但它给了我例外:

  
    

无法确定成员(b.DeviceId == value(CashMasterWeb.Controllers.OptimizationController +<> c__DisplayClass2).component.ParentDevice.DeviceId)

  
     

异常详细信息:System.Exception:无法确定成员   (b.DeviceId ==   值(CashMasterWeb.Controllers.OptimizationController + LT;> c__DisplayClass2).component.ParentDevice.DeviceId)

     

来源错误:

     

第81行:ComponentTemplate template = null;第82行:第83行:                 var query = _cmSession.QueryOver(()=> profile)第84行:.JoinQueryOver(x => x)第85行:.JoinAlias(a => a.HardwareProfileId,()=>模板,JoinType.LeftOuterJoin )

0 个答案:

没有答案