Condiciones de NHibernare JoinQueryOver

I have a inner join condition in sql that look like this:

SELECT
    UniqueID
FROM
    Manuscripts M
    inner join
        Workflows W
            on M.WorkflowID=W.WorkflowID 
    inner join
        WorkflowSteps WS
            on W.WorkflowID=WS.WorkflowID 
            and WS.WorkflowStepID = W.LastStepID 
WHERE
    M.IssueID = ? 
    and W.LastStepID is not null
    and WS.ActualEnd is null

I was translating the query to nhibernate and so far I'm unable to define the additional join condition, my query is as following:

Workflows workflow = null;
WorkflowSteps workflowStep = null;

return session.QueryOver<Manuscripts>()
    .Where(p => p.Issues == Issue)
    .Inner.JoinQueryOver(p => p.Workflows, () => workflow)
    .WhereNot(p => p.LastWorkflowStep == null)
    .Inner.JoinQueryOver(p => p.WorkflowSteps, () => workflowStep)
    .Where(() => workflowStep.DateActualEnd == null)
    .Select(p => p.UniqueId)
    .List<string>();

How can I add the additional condition to the join using the criteria API?

Many thanks, Pedro

preguntado el 08 de noviembre de 11 a las 12:11

1 Respuestas

I don't know if it's possible to add additional join conditions, but since you are using an inner join you can just place the additional condition in the where part of the query.

respondido 08 nov., 11:16

I’m afraid that doesn't work. .Inner.JoinQueryOver(p => p.WorkflowSteps, () => workflowStep) .Where(() => workflowStep.DateActualEnd == null) .And(() => workflowStep == workflow.LastWorkflowStep) That was also my initial approach but didn't work. - Pedro

@Pedro Why doesn't it work? Does it throw exceptions or generate invalid SQL? Please post more information. - cremor

Yes it throws an exception of object reference not set, before the SQL is generated. Which I think relates to the join condition, somehow nhibernate cannot create the join condition using the query above. - Pedro

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.