Optional Foreign Keys to same table

Thread is closed for posting
4 posts, 0 answers
  1. Urs
    Urs avatar
    15 posts
    Member since:
    Jun 2012

    Posted 19 Nov 2008 Link to this post

    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
  2. Urs
    Urs avatar
    15 posts
    Member since:
    Jun 2012

    Posted 20 Nov 2008 Link to this post

    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.
  3. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 24 Nov 2008 Link to this post

    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.
  4. Urs
    Urs avatar
    15 posts
    Member since:
    Jun 2012

    Posted 24 Nov 2008 Link to this post

    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
Back to Top