This is a migrated thread and some comments may be shown as answers.

Optional Foreign Keys to same table

3 Answers 140 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Urs
Top achievements
Rank 2
Urs asked on 19 Nov 2008, 08:43 AM
I have:
- OpenAccess 4.4.0.48
- SQL Server 2005

I want:
An class (table) that has an optional (nullable) reference to an instance to the same class.

OpenAccess does:
OpenAccess does NOT create a foreign key constraint which would be possible in SQL Server. Why not?
OpenAccess removes my self created foreign key on every build.

How can I configure OpenAccess to create the constraints?
Or how can I configure OpenAccess to not remove the constraints?

Thanks in advance.
Urs Scherrer

3 Answers, 1 is accepted

Sort by
0
Urs
Top achievements
Rank 2
answered on 20 Nov 2008, 07:40 AM
Another point that blocks me now:
If I add the constraints manually, I cannot insert the records anymore because OpenAccess obviously does not call the inserts in the same sequence as the "AddObject" Statements....

So inserting fails becuase referenced records are not inserted yet.

Maybe if OpenAccess knows about the contstraint it keeps track of the sequence?

Thanks in advance.
0
Jan Blessenohl
Telerik team
answered on 24 Nov 2008, 10:26 AM
Hi Urs,

Exactly because of those problems we are not generating the constraint. We have a mechanism detecting circles in your model definition and whenever we find such a circle, in your case a short one, we do not add the constraint.

It would be possible to detect those things during runtime and split the insert into 2 phase to do the insert and an update of the fk later but that id really complicated.

All the best,
Jan Blessenohl
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Urs
Top achievements
Rank 2
answered on 24 Nov 2008, 11:00 AM
Hi Jan

Thanks for the confirmation of the behaviour.

So it's a pity that I cannot have a tight datamodel. A simple solution could be to keep track of the sequence. Then it would be my responsiblity to do the inserts correctly. Like it is in SQL...

Now I have to loosen the datamodel and write some code to ensure, that data cannot be logically "corrupted". Alos I cannot guarantee, that all cases were checked.


I'm  sure you will find a solution in future releases.

Urs
Tags
General Discussions
Asked by
Urs
Top achievements
Rank 2
Answers by
Urs
Top achievements
Rank 2
Jan Blessenohl
Telerik team
Share this question
or