Sllix
Sllix

Reputation: 606

Use IQueryable<AnonymousType> in second join

I have a query with multiple joins. My first query works perfect, but when I want to use this result (IQueryable) in my second join, I get an error. How can I use my first result object in my second query?

thanks!

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

Upvotes: 3

Views: 1269

Answers (1)

Ahmed KRAIEM
Ahmed KRAIEM

Reputation: 10427

You are affecting the result of the second Join... to qry, they haven't the same type.

Use a different variable:

var result = notifications.Join(qry, 
                        n => n.DatabaseID, 
                        anon => anon.Ticket.DatabaseID, 
                        (n, anon) => 
                            new {Ticket = anon.Ticket, 
                                Approval = anon.Approval, 
                                Notification = n});

Upvotes: 4

Related Questions