我试图在没有单个根实体的情况下获取多个实体(实体关系的有向图只是一个弱连接图,而不是强连接图),我无法弄清楚如何在 Nhibernates QueryOver api(或 Linq,但是这似乎更弱)
这些是我的关系:
ClientTaxEntity
参考文献 1Client
和 NManufacturers
InstructionTemplate
参考文献 1Client
和 1Manufacturer
我想获得所有可能的客户-制造商对的结果(可能 = 它们在 ClientTaxEntity 中一起),如果存在则为它们获取模板(否则为 null)
这是我到目前为止所尝试的:
Client client = null;
Manufacturer manufacturer = null;
InstructionTemplate template = null;
ClientTaxEntity taxEntity = null;
InstructionTemplateInfo info = null;
var query =Session.QueryOver<ClientTaxEntity>(() => taxEntity)
.JoinAlias(x => x.Client, () => client)
.JoinAlias(x => x.Manufacturers, () => manufacturer)
.Left
.JoinQueryOver(() => template, () => template,() => template.Client == client && template.Manufacturer == manufacturer);
var result = query
.SelectList(builder => builder
.Select(() => client.Name).WithAlias(() => info.ClientName)
.Select(() => client.Id).WithAlias(() => info.ClientId)
.Select(() => manufacturer.Name).WithAlias(() => info.ManufacturerName)
.Select(() => manufacturer.Id).WithAlias(() => info.ManufacturerId)
.Select(() => template.Id).WithAlias(() => info.TemplateId)
.Select(() => template.Type).WithAlias(() => info.Type)
)
.TransformUsing(Transformers.DistinctRootEntity)
.TransformUsing(Transformers.AliasToBean<InstructionTemplateInfo>())
.List<InstructionTemplateInfo>();
info 对象是我想要的结果。
但是,语法.JoinQueryOver(() => template
似乎对路径参数无效(异常表示:could not resolve property: template of: ClientTaxEntity