سؤال

I'm trying to restrict a left outer join with a simple restriction but it fails with an sql exception.

System.Data.SqlClient.SqlException: Must declare the scalar variable "@p1".

My ICriteria:

 var r = session.CreateCriteria<Parent>("p")
.CreateCriteria("p.Children", "c", NHibernate.SqlCommand.JoinType.LeftOuterJoin, Restrictions.Eq("c.Name", "John Doe"))
.List();

The desired SQL:

SELECT * FROM Parents p
LEFT OUTER JOIN Children c ON c.ParentID = p.ID AND c.Name = 'John Doe' 

Do I have to add the variable values in any way? The SQL generated by NHibernate is correct but the variable just isn't sent to the server.

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top