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
|
Hi Guys, Let me start by thanking you for your rapid response to my last post, it was very very helpful. I have for arguments sake a user table and every user has an address. In the database the is a user table and an address table, the address table has nullable columns as it could possibly be an international address or a local address. I was hoping to have two entities, being international address and local address that link to the same table but retrieve different data. I can not for some reason get this working, is this scenario supported by lightspeed? Kind Regards, Josh |
|
|
Yes, you can do this using single table inheritance, but your Address table will need an (e.g.) AddressType column to act as a discriminator. Then you can have AddressType 1 be international and AddressType 2 be domestic: public class Address : Entity<int> { /* common fields */ } The Country column will be loaded only for International addresses and the Postcode only for Domestic addresses. When reading from the database, LightSpeed will automatically create the right derived type of entity by looking at the discriminator; and when writing to the database, LightSpeed will automatically fill in the discriminator based on the specific entity type. If you're using the designer, just draw inheritance arrows from InternationalAddress to Address and DomesticAddress to Address, and set up the discriminator name and value via the arrows' properties window. See also Inheritance in the docs. |
|
|
Hi there, what if the column used as a discriminator is in a different table that has foreign key linked to, how would you resolve this problem? Thanks in advance.
|
|
|
Sorry, that's not supported. The discriminator must be in the same table as the entities. What's the scenario you're trying to address here? |
|