Table-per-subclass?

Posts   
1  /  2
 
    
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 28-Sep-2006 09:22:37   

I dont understand. If I have this:

EntityA, relates 1:n with EntityC, where EntityC is part of a hierarchy with EntityB the parent.

Now, I have an instance of EntityA. EntityA has a property that will pull all EntityB's into a collection.

However, that is not what I want. I want a property that pulls all EntityC's in - so how do I do that without this relationship?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 28-Sep-2006 10:24:25   

WayneBrantley wrote:

Warming this thread up......I had this same problem and am trying to summarize the conclusions from above.

1) When adding a custom relation, you cannot uncheck the 'Also add this relation to the related entity'. If you do, the code will not compile. There is no workaround - just don't uncheck that box.

In selfservicing, you can't hide/use singlesided relations, that's a given. In adapter you can. As the designer doesn't work with what you choose for templategroup, you are allowed to uncheck that box, but you have to realize what you're doing.

One decision I made a couple of years ago was that LLBLGen Pro isn't for completely non-developers: it's a developer tool, therefore I can and will assume a certain level of understanding how software works, that you have to read manuals and in general that you have to know what you're doing (to some extend of course simple_smile ). So when you add a relation on one side, and you're planning to use selfservicing, you've to realize that you have to add the other side of the relation as well.

2) The reason I would want to uncheck the box in #1 above, is because the entity I am relating it to has already inherited this relationship as it is part of a TargetPerEntity hierarchy. Letting it add this relationship results in duplicate unused code - and by default names the property the same as an already existing property causing a compile error. (This is of course fixed by renaming the property on the designer).

If a relation is already inherited you don't have to add it again, as it's already there.

Is that pretty much the case?

*Edit: I have a relationship EntityA to EntityB 1-n. EntityB is part of a hierarchy with EntityC a child of that hierarchy. So, when I add a relationship to EntityA for EntityC, I am still getting a compile error even if I do not uncheck that box. I am getting a duplicate IEntityRelation name. In the EntityCRelations.cs file, I have TWO relations of EntityAUsingEntityAPKey.

So, nothing working for me...for now, I am commenting out this extra relation when I build.

This is simple inheritance: EntityC is-a EntityB. So all relations of EntityB are owned by EntityC as well, because it IS an entityB as well. So adding another relation to entityC which is actually the same as a relation from entityB is redundant and also wrong, because what does the inherited relation mean when you look at the relation you want to add?

WayneBrantley wrote:

I dont understand. If I have this:

EntityA, relates 1:n with EntityC, where EntityC is part of a hierarchy with EntityB the parent.

Now, I have an instance of EntityA. EntityA has a property that will pull all EntityB's into a collection.

However, that is not what I want. I want a property that pulls all EntityC's in - so how do I do that without this relationship?

You specify a filter on the type of EntityC, so only EntityC's are returned.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 28-Sep-2006 19:06:37   

Otis wrote:

WayneBrantley wrote:

I dont understand. If I have this:

EntityA, relates 1:n with EntityC, where EntityC is part of a hierarchy with EntityB the parent.

Now, I have an instance of EntityA. EntityA has a property that will pull all EntityB's into a collection.

However, that is not what I want. I want a property that pulls all EntityC's in - so how do I do that without this relationship?

You specify a filter on the type of EntityC, so only EntityC's are returned.

I have removed these relations and written some code (WHAT? I thought your product did everything for me smile ). Here is what I am still not understanding:

You have an entity - call it CarLot. It is 1:n related to an inheritance hierarchy called 'Car'. There are 2 derrived entity - call them DerrivedCar1 and DerrivedCar2.

From my code, I would like to reference carLot.DerrivedCar2 and carLot.DerrivedCar1 as well as carLot.Car. I would like to have any or all of these prefetched using a prefetch path.

From the above discussion, the only thing I can do is to: 1) Prefetch the entire car collection and define entityviews as a DerrivedCar1 property. This property would show only the correct entity. 2) Write some code as a DerrivedCar1 property that just does the entire fetch from the database. In this instance, it rules out prefetch paths - but makes it where you do not have to bring the entire car collection in if you only want a subset of them.

Using option 2, I have written this in CarLotEntity:

private DerrivedCar1Collection _derrivedCar1;

public DerrivedCar1Collection DerrivedCar1
{
    get
    {
        if (_derrivedCar1 == null)
        {
            _derrivedCar1 = new DerrivedCar1Collection();
            _derrivedCar1.GetMulti(DerrivedCar1Fields.CarLotId == this.CarLotId);
        }
        return _derrivedCar1;
    }
}

It just seems to me that I have a relationship of CarLot->Car. I add derrived types of Car, like DerrivedCar1. That means I could/should have another relationship from CarLot->DerrivedCar1, complete with prefetchpaths and everything. (Me trying to add that relationship is what started all this. And it WORKS to add that relationship, except the code generated has a duplicate 'Relation' with the same name..)

Is this not possible? Or what are your thoughts?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 29-Sep-2006 12:44:59   

WayneBrantley wrote:

Otis wrote:

WayneBrantley wrote:

I dont understand. If I have this:

EntityA, relates 1:n with EntityC, where EntityC is part of a hierarchy with EntityB the parent.

Now, I have an instance of EntityA. EntityA has a property that will pull all EntityB's into a collection.

However, that is not what I want. I want a property that pulls all EntityC's in - so how do I do that without this relationship?

You specify a filter on the type of EntityC, so only EntityC's are returned.

I have removed these relations and written some code (WHAT? I thought your product did everything for me smile ). Here is what I am still not understanding:

You have an entity - call it CarLot. It is 1:n related to an inheritance hierarchy called 'Car'. There are 2 derrived entity - call them DerrivedCar1 and DerrivedCar2.

From my code, I would like to reference carLot.DerrivedCar2 and carLot.DerrivedCar1 as well as carLot.Car. I would like to have any or all of these prefetched using a prefetch path.

You can't. DerivedCar1 and DerivedCar2 will be in carLot.Cars. If you want Cars to be filled with a limited set, you should call GetMultiCars with a filter.

If you want to use a prefetch path for Cars, you can also specify a filter, but that's it. The collection carLot.DerivedCar2s is redundant, it's a subset of carLot.Cars.

If you remove the relation carlot-Car and add individual relations, you can do it but you have to add relations to all the cartypes.

From the above discussion, the only thing I can do is to: 1) Prefetch the entire car collection and define entityviews as a DerrivedCar1 property. This property would show only the correct entity.

That's another option. EntityView's are meant for this actually: you can view a subset of a complete set, so you can create for each cartype a different view.

2) Write some code as a DerrivedCar1 property that just does the entire fetch from the database. In this instance, it rules out prefetch paths - but makes it where you do not have to bring the entire car collection in if you only want a subset of them.

Using option 2, I have written this in CarLotEntity:

private DerrivedCar1Collection _derrivedCar1;

public DerrivedCar1Collection DerrivedCar1
{
    get
    {
        if (_derrivedCar1 == null)
        {
            _derrivedCar1 = new DerrivedCar1Collection();
            _derrivedCar1.GetMulti(DerrivedCar1Fields.CarLotId == this.CarLotId);
        }
        return _derrivedCar1;
    }
}

It just seems to me that I have a relationship of CarLot->Car. I add derrived types of Car, like DerrivedCar1. That means I could/should have another relationship from CarLot->DerrivedCar1, complete with prefetchpaths and everything. (Me trying to add that relationship is what started all this. And it WORKS to add that relationship, except the code generated has a duplicate 'Relation' with the same name..) Is this not possible? Or what are your thoughts?

It's not possible, as it's redundant. You want a property which is actually simply returning a subset of another collection in the same class. This is the same as when I want a property added to customer with the orders of last year.

Frans Bouma | Lead developer LLBLGen Pro
1  /  2