0
        // load the client and any many to one relationships
        var clientRootQuery = session.QueryOver(() => clientAlias);
        clientRootQuery.Left.JoinAlias(() => clientAlias.Person, () => personAlias)
        .Left.JoinAlias(() => personAlias.SexType, () => sexTypeAlias)
        .Left.JoinAlias(() => personAlias.EyeColorType, () => eyeColorTypeAlias)
        .Left.JoinAlias(() => clientAlias.Organization, () => organizationAlias)
        .Left.JoinAlias(() => clientAlias.ClientStatusType, () => clientStatusTypeAlias)
        .Left.JoinAlias(() => clientAlias.Notes, () => noteAlias)
        .Left.JoinAlias(() => noteAlias.Comments, () => commentAlias)
        .Where(() => clientAlias.Id == clientId)
        .Future<Client>();

        // load the note collection into the nhibernate session 
        // todo ******************** this doesn't work.  nhibernate is still firing off queries in the adapter fill method rather than using the values pulled here.
        var notes = session.QueryOver(() => clientAlias)
        .Left.JoinAlias(() => clientAlias.Notes, () => noteAlias)
        .Left.JoinAlias(() => noteAlias.Comments, () => commentAlias)
        .Where(() => clientAlias.Id == clientId)
        .Future<Client>();

return clientRootQuery.Take(1).SingleOrDefault();

这不会返回客户端对象上的许多地址,也不会返回许多注释。这应该有效。有一个客户有很多笔记和很多地址。

有任何想法吗?

4

2 回答 2

0

clientAddresses 未初始化的原因是因为您在它们上设置了过滤器,因此 NHibernate 假定并非所有 clientAddresses 都已加载以完全初始化集合。

于 2012-06-25T14:04:38.120 回答
0
var clientRootQuery = session.QueryOver(() => clientAlias)
        .Left.JoinAlias(() => clientAlias.Person, () => personAlias)
        .Left.JoinAlias(() => personAlias.SexType, () => sexTypeAlias)
        .Left.JoinAlias(() => personAlias.EyeColorType, () => eyeColorTypeAlias)
        .Left.JoinAlias(() => clientAlias.Organization, () => organizationAlias)
        .Left.JoinAlias(() => clientAlias.ClientStatusType, () => clientStatusTypeAlias)
        .Where(() => clientAlias.Id == clientId)
        .Future();

 var notes = session.QueryOver(() => clientAlias)
        .Left.JoinAlias(() => clientAlias.Notes, () => noteAlias)
        .Where(() => noteAlias.Client.Id == clientId)
        .Future();

var list = clientRootQuery.ToList();
        return list.FirstOrDefault();

它必须是左连接。

于 2012-06-25T14:09:55.937 回答