Let's assume that there is a table named Setting:
- id
- name
- category
- text_value
- int_value
Based on this table is a flat inheritance hierarchy designed, with "category" as the class discriminator
- Setting as a top class (category = 'X'); includes columns: id, name, category
- SettingText: category = 'T'; includes column: text_value
- SettingInt: category = 'I'; includes column: int_value
There is an existing object - SettingText. I would like to change it to SettingInt. From the database point of view it's easy: just set category = 'I' (I know that I loose the text_value column content). But how to do it using ORM mechanisms? I can't just cast SettingText to SettingInt. Deleting the old object and creating a new one is not always possible (it may be an FK somewhere). Have you got any suggestions?
Regards
Tomasz
7 Answers, 1 is accepted
I think in this particular case using inheritance is not very appropriate due to impossible casting. I suggest you using only one class that has both text and int fields. You can have additional bool field (for example isText) that takes the role of a discriminator.
Best wishes,
Alexander
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
It's not good but I must learn to live with it :-)
Thanks
Tomasz
to me this sounds not so much as morphing an object type but more like an 'posing-as' scenario.
Depending on a user controlled discriminator, the object behaves different. You can do exactly that when all columns are included in the type (flat mapping) and you decide in your code which route to take depending on the category value.
Regards,
Thomas
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Thanks for advises. You are right, of course, but I'm not a fan of the "switch" statement :-)
Regards
Tomasz
Hi,
Of course, you are right - in the sense that if it is a problem, it should be re-thought, re-designed and so on. My original post is rather a theoretical question than a practical problem to be solved.
Thanks for your adivises, too.
Regards
Tomasz
Regards,
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.