parent-child selection criteria bug.

6 views
Skip to first unread message

John Lewis

unread,
Jun 12, 2008, 10:33:54 AM6/12/08
to rhino-t...@googlegroups.com
I found what I think is a bug in NHibernate.Linq. On a parent-child relationship, trying to select all children that do not have a parent. All the details and sourcecode can be found at http://aspzone.com/tech/nhibernate-linq-troubles/
 
If you would not mind, could you confirm if this is a bug, or something wrong that I am doing?
 
Thanks.

Chadly

unread,
Jun 12, 2008, 11:10:28 AM6/12/08
to Rhino Tools Dev
Yes, this is a bug. This was the last bug I was working on. I
haven't had the time to really delve into it recently. I'll see about
coming up with a resolution for it this weekend. I am running into it
in some of my own code as well.

On Jun 12, 9:33 am, "John Lewis" <johnrle...@gmail.com> wrote:
> I found what I think is a bug in NHibernate.Linq. On a parent-child
> relationship, trying to select all children that do not have a parent. All
> the details and sourcecode can be found athttp://aspzone.com/tech/nhibernate-linq-troubles/

Ayende Rahien

unread,
Jun 12, 2008, 1:01:12 PM6/12/08
to rhino-t...@googlegroups.com
Fixed.
Chadly, can you take a look and see if this is wrong somehow? I haven't touched the code in a while.

Another issue, how are we implementing the functions in Linq?
I am talking about things like this:

var query = from e in db.Employees
                        where db.Methods.Substring(e.FirstName, 1, 2) == "An"
                        select db.Methods.Left(e.FirstName, 3);

Chadly

unread,
Jun 12, 2008, 3:18:04 PM6/12/08
to Rhino Tools Dev
I don't think that fix will work with slightly more complex queries --
for instance:

this now works:

from s in session.Linq<Role>()
where s.ParentRole != null
select s;

but this query returns the wrong results:

from s in session.Linq<Role>()
where s.ParentRole.Name != null
select s;

The fundamental issue lies in MemberNameVisitor.VisitEntity line 77:

if (expr.Type != _rootCriteria.GetRootType())

It will not create a subcriteria for the root type. This creates
problems for hierarchical queries like the one in the example.

My generic solution to the problem was trying to assign aliases to
each entity in the query in order to distinguish each EntityExpression
by alias rather than entity type. Although, that proved to be more
difficult than I originally estimated. I'll take a deeper look at it
this weekend.

As far as the DB functions go, not sure what happened to that
implementation. Those tests have been failing for a long time -- I
never took a look to see what was wrong.

On Jun 12, 12:01 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> Fixed.
> Chadly, can you take a look and see if this is wrong somehow? I haven't
> touched the code in a while.
>
> Another issue, how are we implementing the functions in Linq?
> I am talking about things like this:
>
> var query = from e in db.Employees
> where db.Methods.Substring(e.FirstName, 1, 2) ==
> "An"
> select db.Methods.Left(e.FirstName, 3);
>

Ayende Rahien

unread,
Jun 13, 2008, 12:36:37 PM6/13/08
to rhino-t...@googlegroups.com
Okay, I'll let you take care of it, didn't consider the more complex route.
Reply all
Reply to author
Forward
0 new messages