Fetching Super Type without Sub Type

Posts   
 
    
anton55
User
Posts: 1
Joined: 19-Jan-2011
# Posted on: 19-Jan-2011 10:45:51   

Hi Guys,

After reading Otis's post on OMR performance I downloaded LLBLGenProfiler. Should have done it way sooner!!

I'm using subtyping successfully but in many valid cases there is a need to get just the data for the super type entity without the mad left joins to the subtypes and caring about any inheritance.

#region -- method 1

        GameInstanceEntity g = new GameInstanceEntity(new Guid("702D6644-456E-DF11-94A4-08002700DCE4"));
        da.FetchEntity(g);
        #endregion

        #region -- method 2

        EntityCollection<GameInstanceEntity> baseItems = new EntityCollection<GameInstanceEntity>(new GameInstanceEntityFactory());
        IEntityFields2 fields = baseItems.EntityFactoryToUse.CreateFields();
        List<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
        for (int i = 0; i < fields.Count; i++)
        {
          IEntityField2 field = fields[i];
          valueProjectors.Add(new DataValueProjector(field.Name, i, field.DataType));
        }

        RelationPredicateBucket filter = new RelationPredicateBucket(GameInstanceFields.GameInstanceId == new Guid("702D6644-456E-DF11-94A4-08002700DCE4"));

        DataProjectorToIEntityCollection2 projector = new DataProjectorToIEntityCollection2(baseItems);
        da.FetchProjection(valueProjectors, projector, fields, filter, 0, true);

        #endregion

method 1 produces sql that left joins to 18 tables!

method 2 produces sql that just fetches the gameinstance entity with no joins to subtypes.

Surely there must be a simpler way to perform method 2 in syntax similar to method 1?

Please please!!!

I'm on version 2.6 and this would be a great reason to move to 3

Many thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 19-Jan-2011 16:52:05   

You can create a method for producing the dataprojectors from an entity type, by obtaining the factory using EntityType and the GeneralEntityFactory or the EntityFactoryFactory. This will make things easier for fetching.

You can also map another entity onto the same table. This will not join the entities, but this is less ideal.

Having 18 tables in an inheritance hierarchy is really a lot. You will likely want to break things up in smaller hierarchies or use encapsulation instead of inheritance. E.g. use the 1:1 relationships between entities instead of creating a deep hierarchy.

Frans Bouma | Lead developer LLBLGen Pro