one-to-one relationship

Nov 4, 2009 at 8:50 AM

I would like to define class like

class Person
{
int PersonID; 
string Name;
  ...
  Person Boss;
}

Some kind of "self referencing". In the database, field Boss should be foreign key to PersonID (same table). As I see IQToolkit doesnt' support this kind of relationship. Where should I look into (which class), to excend/change IQToolkit to support this?

Thanks.

Matej

Coordinator
Nov 8, 2009 at 6:11 AM

The toolkit does support 1:1 relationships.  You have to also specify the field that is the foreign key id in your object (in addition to the field that is the reference.)

Nov 8, 2009 at 10:27 AM

Thanks for answer. I canno't find any example how to do it. As I understand I have to "specify" (via mapping (atributes/xml..)?) to member Boss some additional info (boss_id for example)?

Nov 8, 2009 at 6:52 PM

I found foreign key example inside Nortwind example

[Association(Member = "Customer", KeyMembers = "CustomerID", RelatedEntityID = "Customers", RelatedKeyMembers = "CustomerID")]

Problem is that it doesn't work as exceptect. If I wrote simple query (on your test)

from c in db.Orders
where c.Customer != null
select c;
it throws exception inside SQLformatter (The LINQ expression node of type 1017 is not supported). Any hint?

Nov 9, 2009 at 8:19 AM

If I try with my first case (self referencing) iw works just for first level.

so query like :

for c in db.Person
where c.Boss.PersonID != null

works OK but it doesnt work if I nest ones more

for c in db.Persion
where c.Boss.Boss.PersonID != null

It looks that IQtoolkit doesn't support nested foreign key.

Dec 19, 2009 at 5:13 AM

@matejgolob - are you sure you set the QueryPolicy to load that relationship?

Dec 20, 2009 at 10:56 AM

Yes I'm sure that I set QueryPolicy. As I wrote, It works for "first" level, but if I nest referencing ones more , it doesnt work well (it looks that "relationship" doesnt work in recursive manner)

 

Coordinator
Jan 4, 2010 at 12:03 AM

Yes, there is a bug here that I've fixed but have not released yet.