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

Create a One-To-One association with DatabaseServerCalculated Identities

4 Answers 62 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Aybe
Top achievements
Rank 1
Aybe asked on 02 May 2013, 12:29 PM
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 !

4 Answers, 1 is accepted

Sort by
0
Accepted
Doroteya
Telerik team
answered on 03 May 2013, 01:51 PM
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 >>
0
Aybe
Top achievements
Rank 1
answered on 05 May 2013, 12:59 PM
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.
0
Doroteya
Telerik team
answered on 09 May 2013, 06:34 AM
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 >>
0
Aybe
Top achievements
Rank 1
answered on 09 May 2013, 09:19 PM
That all makes sense now, thank you !
Tags
Getting Started
Asked by
Aybe
Top achievements
Rank 1
Answers by
Doroteya
Telerik team
Aybe
Top achievements
Rank 1
Share this question
or