Determine if a path starts at an entity

Posts   
 
    
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 13-Jan-2021 23:08:23   

Adapter, 5.7

Is there a faster or better way to do this, determine if the start of a IPrefetchPathElement2 is of a particular entity type?

        static bool StartAtEntityType(IEntity2 entity2, IPrefetchPathElement2 pathElement) 
        {
            return entity2.GetAllRelations().Any(r => r.ToString() == pathElement.Relation.ToString());
        }

I see that IPrefetchPathElement2 has 2 interesting properties, DestinationEntityType and ToFetchEntityType but they are numbers, not Types . Is there for example a way to go from those numbers to a Type or from an IEntityFactory2 or IEntity2 to the number?

(I'm trying to write an entity cloner where I can specify the graph shape via a list of graph paths(edges).)

Thanks,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 14-Jan-2021 09:32:38   

These numbers are int values of the EntityType enum which is in the generated code. So you can cast them to EntityType to see the context. A prefetch path element's destination is the start of the edge, the fetch entity type is the type of entity to fetch. This might be a supertype of subtypes, and the destination type might be a subtype of a supertype, in case of inheritance.

Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 14-Jan-2021 21:22:55   

Thanks, I see that as a private field on the factory

_typeOfEntity = PortCallEntity

But I dont see it public anywhere on the entity (IEntity2) or the factory (IEntityFactory2) that I can use to compare with the IPrefetchPathElement2. Am I missing something?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39888
Joined: 17-Aug-2003
# Posted on: 15-Jan-2021 10:09:53   

It's protected: protected int GetEntityTypeValue() You can also obtain the metadata for an entity (also using a protected method, so you have to add a method to a partial class of the CommonEntityBase class to obtain it using a public API: call GetEntityStaticMetaData()to obtain the meta data of an entity. You can't return the object of that method as it's protected, but you can obtain the info you need and return that. We didn't expose these APIs publicly to avoid clutter in the already crowded public API of an entity.

Frans Bouma | Lead developer LLBLGen Pro
yowl
User
Posts: 271
Joined: 11-Feb-2008
# Posted on: 15-Jan-2021 20:46:11   

Thanks for the pointer. Works for me.