Create a One-To-One association with DatabaseServerCalculated Identities

5 posts, 1 answers
  1. Aybe
    Aybe avatar
    3 posts
    Member since:
    Mar 2013

    Posted 02 May 2013 Link to this post

    Hello,

    Whenever I try to define such association, I get the following error message :
    The source class of the 'MediaHasUpload' 1:1 association uses backend calculated identity. This is not allowed because the foreign key value should be obtained from the identity of the target class. Consider defining the association in the opposite direction.
    (Both classes have a DatabaseServerCalculated identity)

    Basically what I'm looking for is to have a 'Media' class with a DatabaseServerCalculated identity, the 'Media' can have an 'Upload' class property that can be null. I've tried to set the 'Upload' identity to DatabaseServerCalculated so it gets created for me but then that error is triggered.

    How can such association be defined, if possible at all ? If not, what would be the closest compromise to it ?

    Thank you

    UPDATE

    I fixed it -> using a GUID instead it's working now !
  2. Answer
    Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 03 May 2013 Link to this post

    Hello Aybe,

    Thank you for the update. I am glad that currently, everything works fine on your side.

    Let me just add that the error you experience is caused from the fact that both classes have DatabaseServerCalculated set for the identity mechanism. You can avoid it by using this setting only for the Media class.

    Additionally, consuming the model in the necessary way is provided by the isManaged and isDependent properties that can be set for the navigation properties of the classes. Here you can find how to insert related objects in the database and here - how to delete related objects.

    If you have other questions or if you experience difficulties, do not hesitate to get back to us.


    Kind regards,
    Doroteya
    the Telerik team
    Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
  3. DevCraft banner
  4. Aybe
    Aybe avatar
    3 posts
    Member since:
    Mar 2013

    Posted 05 May 2013 Link to this post

    Hello,

    It works now but it's a little counter-intuitive as the association to create must be UploadHasMedia and not MediaHasUpload, why this ?
    Or is it the way it's meant to be working ?

    Thank you.
  5. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 09 May 2013 Link to this post

    Hi Aybe,

    Generally, the names of the associations are based on the fact that the associations actually model constraints. In other words, the design of the database in your case does not allow an upload to exist without a media (Upload always Has Media). While the other way around is acceptable: you can have media that does not have uploads (Media not always Has Upload).

    With this naming convention you unambiguously know which one of the classes holds the primary key and which one holds the foreign key.

    Additionally, you can rename the association in either Association Editor or the Properties window.

    If you have additional questions, do not hesitate to get back to us.


    Greetings,
    Doroteya
    the Telerik team
    Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
  6. Aybe
    Aybe avatar
    3 posts
    Member since:
    Mar 2013

    Posted 09 May 2013 Link to this post

    That all makes sense now, thank you !
Back to Top
DevCraft banner