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

[Solved] Inheritance and key generator

1 Answer 152 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.
Tajes
Top achievements
Rank 1
Tajes asked on 09 Mar 2011, 05:25 PM
Hello,
I've a problem with the key generator in a subclass entity. I've two classes, one parent class and one subclass, using flat like subclass inheritance strategy, and default strategy in the superclass, with only one table for both classes. I'm using visual designer, and I set backend calculated in the identity mechanism of parent class.
I cannot set any Identity Mechanism in the subclass, and when I add a subclass object to the context and save the changes, the object always has 0 like ID. I cannot set autoinc in the database because an error is raised when I try to add a new object to the context, telling that the subclasses cannot have key generator set.
How can I make works the key generator in the subclass?

Thanks in advance, and sorry for my English

1 Answer, 1 is accepted

Sort by
0
Accepted
Zoran
Telerik team
answered on 14 Mar 2011, 10:05 AM
Hello Tajes,

 As the base and subclasses are mapped in one table and one table can have only one primary key - in flat inheritance scenarios you can set the primary key and identity mechanism(Key Generator) on the base class only. All of the subclasses will use the same property/column for storing their identity and the key generator will also be the same. That also applies for vertical inheritance as the base class table there has a 1:1 constraint relation with the tables of the subclasses. Only horizontal inheritance allows different Key generators for the subclasses.

To recap, what you should do is to set all of the members in the subclass with Identity=false and chose an identity member in the base class. You can set the identity mechanism on the base class then and it will apply for the subclass as well.

Greetings,
Zoran
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
General Discussions
Asked by
Tajes
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or