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
|
Hello, Consider the following class hierarchy:
I have implemented Resource and SecurableResource to share implementations and was never intended to be tables. However, LightSpeed wants to use a table "resources". How do I'd like to indicate to LightSpeed that Product and User are "root" entity types, however the properties such as CreatedOn etc defined in Resource should also exists in the "products" and "users" table. I have no plan to create queries related to "Resource" or "SecurableResource" base types. Thanks, Werner |
|
|
You will want to use concrete table inheritance for this. e.g. In the designer add Resource, SecurableResource, Product and User as entities.
If you now sync with the database it should create 2 tables - Product and User and include all of the underlying properties in Resource and SecurableResource. Queries against these will use Product and User as the tables for access.
|
|
|
Thanks Jeremy. Following this process, there is a bug in the designer when you create a migration. While the "Up" method creates the correct tables, the "Down" method also wants to delete the abstract tables. Werner |
|
|
I don't really use the designer that much. When I look at the source, I see no difference except that the UnitOfWork doesn't have queries for the abstract type. However, almost all code I write is against IUnitOfWork and LightSpeedContext. How does this work behind the scenes? I ask the question so that I can avoid problems. Thanks, Werner |
|
|
Unfortunately there seems to be a problem. Using the designer, I created an entity called "Resource" and another called "Sample" and followed the instructions such that Sample inherits from Resource. Resource has CreatedOn, UpdatedOn, LockVersion etc. Sample has "Name". When I try to insert a "Sample" the following statement is generated, which is clearly incorrect.
I'm using MySQL 5. Werner |
|
|
ConcreteTableInheritance is defined as inheriting from a base class which is not Entity I will have a look into the migration issue - thanks for alerting us to this :)
|
|
|
What does your model code look like? Im not seeing this behavior on the example here which I set up yesterday.
|
|
|
Here is the model:
|
|
|
The fields are defined on both the base class and the derived class, you should delete these off the derived class (assuming these are a concern you want covered by the base class).
|
|
|
Mmm, it seems that the designer isn't intelligent enough to figure out that the hierarchy already contains those fields. So whenever you add a new entity, the default policy is applied, and when you configure the inheritance, it doesn't ignore any policies set on the subclasses. However, if I use SingleTableInheritance, those properties are ignored. I assume this may be another bug that I was unaware of. Werner |
|
|
Yep thats right, the designer doesn't try and detect these kinds of issues. The defaults policy isn't actually persisted against an entity after it has been created on the design surface so this isn't something that is considered when configuring inheritance. STI behaves differently because the base classes are considered for mapping where as with Concrete Table Inheritance we just import the fields verbatim on the basis that you have implemented it as you want it to behave so likely something we could look at improving on there in terms of designer warnings.
|
|