This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hey guys! I asked Andrew a question about inheritance mapping the other day and he said that you guys use a Single Table Inheritance model. I was just wondering if there were any "special" columns that needed to be included when inheritance was being used? e.g. a "type" column like that used in Rails... The other thing I was wondering about are the columns catering for fields down the tree - I imagine they would have to be nullable e.g. Say I have: class Person : Entity<Guid>{ private string _name; } class Employee : Person { private string _identificationCode; } class Manager : Person { private int _monthlyBudget; } would my table create statement look (ignore any bung sql syntax): create table Person( id uniqueidentifier rowguid default (newid()), name varchar(255) NOT NULL, identificationCode varchar(20) NULL, monthlyBudget int NULL -- plus any other possible "special" columns here. note the idenficationCode and monthlyBudget columns are NULL - i imagine this is how it should work... )
Cheers guys, James |
|
|
Hi James, You need to use the Discriminator attribute like so:
This allows you use one of your existing fields (if you have one) rather than needing a separate one. Derived field columns either need to be nullable or have a default. You can also use a validation attribute to indicate a required field:
Cheers, Andrew |
|
|
Thanks Andrew. Following on from this - would it be possible to have a field automatically used by the framework inside Entity<T> so we don't have to specify a field to use for the descriminator. Then have another overload on the Descriminator attribute where the Attribute string and value can be left empty (have the default value be the name of the class or something like that)? Cheers, James (ps. I know the name Descriminator is used in other frameworks but I was just wondering if another name might be better to describe this case (that is an entity which should be managed by LightSpeed that is not a direct inheritor from Entity<T>) something like "InheritedEntity"?) |
|
|
Hi James, I considered this but decided against it. In my experience it is not uncommon to be able to use some existing field such as a foreign key to a reference data table e.g Customer has CustomerTypeId as a discriminator value. In this case, having a separator field in Entity<T> just adds bloat. I have also thought about whether there is a more user-friendly name for this attribute. I will ponder this some more. Cheers, Andrew.
|
|