C# 通过QueryOver在nHibernate中连接多个表
我在MsSql数据库上有以下表:C# 通过QueryOver在nHibernate中连接多个表,c#,join,nhibernate,aggregate-functions,multiple-tables,C#,Join,Nhibernate,Aggregate Functions,Multiple Tables,我在MsSql数据库上有以下表:组件、设备硬件配置文件、组件模板、现金回收计数器 我需要填写以下变量:int capacity,通过此查询中的数据加载: 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.d
组件、设备硬件配置文件、组件模板、现金回收计数器
我需要填写以下变量:int capacity,通过此查询中的数据加载
:
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和映射如下所示:
类型代码155代表现金回收商
我已经试过这个表达:
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==值(CashMasterWeb.Controllers.OptimizationController+c\uu DisplayClass2.component.ParentDevice.DeviceId)中确定成员
异常详细信息:系统。异常:无法从中确定成员
(b)设备ID==
值(CashMasterWeb.Controllers.OptimizationController+c\u DisplayClass2.component.ParentDevice.DeviceId)
源错误:
第81行:ComponentTemplate=null;第82行:第83行:
var query=\u cmSession.QueryOver(()=>profile)第84行:.JoinQueryOver(x=>x)第85行:.JoinAlias(a=>a.HardwareProfileId,()=>template,JoinType.LeftOuterJoin)
所有的关联都被映射了吗?@Andrew Whitaker,不是真的。这是个问题吗?如果是这样,您建议如何为我的目的映射它们?为了使用NHibernate在表之间
连接
,您需要映射关联。映射外键列是不够的。@Andrew Whitaker,你能为我指出一些参考资料或示例吗?我会尝试找到一个好的指南,但你想查找“与nhibernate的映射关联”或“与nhibernate的一对多”吗