3

我有一个包含多个连接的查询。我的第一个查询运行良好,但是当我想在第二个联接中使用此结果 (IQueryable) 时,出现错误。如何在第二个查询中使用我的第一个结果对象?

谢谢!

ISession session = NHibernateSessionManager.Instance.GetSession(SessionFactoryConfigPath);

IQueryable<Approval> approvals = session.Query<Approval>();
IQueryable<Ticket> tickets = session.Query<Ticket>()
            .Where(t => t.Canceled == null 
                        && t.IsNotified == null);
IQueryable<Notification> notifications = session.Query<Notification>();

var qry = approvals.Join(tickets, 
                            a => a.TicketID, 
                            t => t.ID, 
                            (a, t) => new { Ticket = t, Approval = a });

//here I want to use my IQueryable<Anonymous> object to create my second join.
qry = notifications.Join(qry, 
                        n => n.DatabaseID, 
                        anon => anon.Ticket.DatabaseID, 
                        (n, anon) => 
                            new {Ticket = anon.Ticket, 
                                Approval = anon.Approval, 
                                Notification = n});
4

1 回答 1

4

您正在影响第二个Join...to的结果qry,它们的类型不同。

使用不同的变量:

var result = notifications.Join(qry, 
                        n => n.DatabaseID, 
                        anon => anon.Ticket.DatabaseID, 
                        (n, anon) => 
                            new {Ticket = anon.Ticket, 
                                Approval = anon.Approval, 
                                Notification = n});
于 2013-07-02T14:52:03.663 回答