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
|
I am refactoring my code and have come across the following error that I can't work out how to fix. I have 4 entities: Report,ReportParameter,ReportParameterLink and Parameter. A Report has a one to many link to ReportParameter.A ReportParameter has a many to one link to Parameter. A ReportParamLink has two links to ReportParameter for 'child' and 'parent' (i.e. it stores which ReportParameters are directl linked to each other). I have also got a similar set up for Form,FormParameter,FormParameterLink and Parameter. Form has a couple of of the same fields as Report and FormParameter has a couple of the same fields as ReportParameter so this seemed like an ideal candidate for inheritance. As a first step, I added the entity DisplayItemParameter as a base and inherited FormParameter and ReportParameter from it. I then removed the relationships between FormParameter and Parameter and ReportParameter and Parameter and replaced it with a relationship between DisplayItemParameter and Parameter. The relationship between ReportParameter and Parameter had a backreference aggregate on it, so I added this to the new relationship. All built ok, but when I run the following query I get a System.Reflection.TargetInvocationExcpetion with an inner exception as below : Descendent type [AoteaCentralLive.FormParameter] of type [AoteaCentralLive.DisplayItemParameter] is not discriminated" Query is : Instance.ReportTypes.OrderBy(rt => rt.ReportTypeOrder).WithAggregate("AllReportDetails").ToList() I've norsed something up somewhere, or not set a property or my model is wrong somewhere, but have spent a while trying to find out what and have drawn a blank. Help. (Note that there is a one to many relationship between ReportType and Report) |
|
|
This means that FormParameter is deriving from DisplayItemParameter using concrete table inheritance, but the model is wired up in such a way that CTI is not an option. In your case, this is because of the relationship between DisplayItemParameter and Parameter. For this to work, all the DisplayItemParameters must be in the same table (so that Parameter can have a foreign key to that table). That in turn means you have to use single table inheritance for the DisplayItemParameter hierarchy. [Alternatively, you can think of it as Parameter's reference to DisplayItemParameter having to be polymorphic, and polymorphic references have to use STI -- see previous blog posts about inheritance in LightSpeed.] And consequently derived types of DisplayItemParameter must have a discriminator. What this boils down to is that if you have associations to a base class then the derived classes have to use STI, because if you are using CTI then there is no single table to the associated class to FK to, and no polymorphism. We should probably add a designer validation check for this. |
|
|
Thanks once again Ivan. I had read the inheritance blog post, but obviously not that well, apologies ! |
|