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! A few of my entities share a common collection "Tags". Beside the collection of tags my entities are very different. Is it still a good idea to use the single-table inheritance pattern as described in the documentation? I would end up with one really large table with a lot of null values... Does lightspeed support any other model of inheritance? Or is it possible that all of my entities can have a collection of "Tags" without the need of inheritance? |
|
|
No, this would not be a good case for single table inheritance. As you rightly identify, this would result in a whole bunch of conceptually separate tables being artificially squeezed into one, which would be both inefficient and inelegant. LightSpeed supports two inheritance patterns: single-table inheritance and The Pattern Without A Definite Name, which we (following Martin Fowler) have started referring to as "concrete table inheritance." (See http://martinfowler.com/eaaCatalog/concreteTableInheritance.html.) Concrete table inheritance is appropriate when there is some commonality between entities but they are not similar enough to all go in the same table: it sticks with the "one entity type = one table" pattern. In your case, CTI would mean: * At the database level, all your entities would have different tables, and the "Tags" column would have to appear in each and every one of those tables. * You would *not* be able to load polymorphically. For example, you could not do a Find<Taggable> and get back a collection of Articles, Videos and Pictures drawn from across those tables; instead you would get an error that there was no "Taggables" table. You would have to call Find<Article>, Find<Video> and Find<Picture> separately, resulting in LightSpeed consulting each of those three tables separately. (Whereas with STI you *could* do a Find<Taggable>, and LightSpeed would look in the Taggables table, but would materialise Article, Video and Picture entities based on the discriminator.) Of course once you got the entities back into the object realm, your code could treat them polymorphically; but LightSpeed will not *load* them polymorphically. See also the last few posts in this thread: http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1418 (ignore the discussion about transience; it's not relevant to your question). I should probably write a blog post about this as well! To use concrete table inheritance: * If you are writing entities by hand in C# or VB, you need to do... nothing! Because CTI follows the "table per entity" model, inherited entities will just behave this way by default, expecting to get their own table rather than living in their parents' table. (You only get STI if you ask for it using the DiscriminatorAttribute.) * If you are defining entities in the designer, select the inheritance arrow and set the Inheritance Type to Concrete Table Inheritance. CTI is supported in the designer only from 2.1; if you are on 2.0 you will need to upgrade. Hope this makes sense -- let me know if you have any further questions or need further clarification. |
|
|
I saw that you wrote a blog post abnout this. I has helped me alot, thanks! |
|