Login Skip Navigation LinksWilsonORMapper > Forums Search
Demo Version Demo Version
Download and try for yourself a fully working demo version, including sample apps and documentation.  The only limitation is that the demo version only works inside the debugger.

PayPal Subscribe
Get It All for $50 USD:
WebPortal, ORMapper,
Source Code, All Updates
PayPal

User Login User Login
Log In
 
 
Reset Password

Wilson ORMapper Forums Wilson ORMapper Forums : OPath Queries : OPath query in a self-referencing table

Date Post
9/26/2006 9:08:39 AM Hi folks,

I am new to the whole ORM usage, let alone the OPath language. The helper tool has interpreted the mapping and object correctly. Here's the scenario:

I have a Dog table with columns: Id, Name, Mother, Father, where Mother and Father are self-referencing foreign keys.

If you're familiar with animal breeding then I'm after Dogs resulting from line breeding, i.e. Grandfather/Granddaughter mating. No bluegrass music jokes please...these are Dogs!

In SQL my query looks like:

Select x.*
From dog x
Join dog m on m.id = x.mother
Join dog gp on gp.id = m.mother or gp.id = m.father
Join dog ggf on ggf.id = gp.father and ggf.id = x.father

How on earth would I interpret that into OPath? Any assistance would be immensely appreciated.

Many thanks,
Dany.
10/2/2006 7:24:22 AM

Hi Dany,

Sorry for the delayed reply.  Have you figured this problem out yet?  I’ve been kicking this around a bit but nothing easy is coming to mind... and nothing nearly as efficient as your hand built sql query).

Breaking down your joins, I get the following:

M = Mother
GP = Mother.Mother or Mother.Father
GGF = Mother.Mother.Father or Mother.Father.Father

From this, my best guess is that the following query would be close:

OPathQuery<Dog>("Mother[(Mother.Father.ID = Father.ID) OR (Father.Father.ID = Father.ID)]")

However, I’m pretty sure this is unsupported syntax.  It might just work but I have a feeling you’ll get an error about traversals on both sides of the expression.  If so, that can be solved using the parent traversal operator:

OPathQuery<Dog>("Mother[Mother.Father[ID = ^.^.^.Father.ID] OR Father.Father[ID = ^.^.^.Father.ID]]")

The generated query is going to look really nasty but I have your dataset is pretty small so performance is not terribly important.

Let me know if this works or gets you on the right track.

- Jeff Lanning

10/3/2006 2:19:57 AM Hi Jeff,

I'm so glad to get a response on this :o) It's a fairly important part of this app so I fretted about it a bit. I have not made further attempts to do it with OPath - instead I have kludged it using raw SQL to project just Dog IDs and iterating through the list to get the Dog objects. Nasty!! It's definitely not ideal since one of my original aim for the app is to be as DMBS-neutral as possible.

I will try your OPath query but at the moment I've left OPath alone - especially since I couldn't get it working for a fairly simple query that I posted on another thread.

Cheers,
Dany.