Getting source table name from subtype entity at runtime

Posts   
 
    
AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 27-Nov-2012 19:52:23   

I have entity that is a subtype. How can I retrieve source table name at run time? GetFieldPersistenceInfos() returns empty array. I see generated code calling this.AddElementMapping() on the entity that is a subtype, I just don't know how to get to the table name. I'm using version 3.1.

Thank you.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Nov-2012 03:34:05   

From your previous posts I assume you are using Adapter. So create a new DataAccessAdapter partial class in your DBSpecific generated project and follow this code http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=20908&StartAtMessage=0&#117843

David Elizondo | LLBLGen Support Team
AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 28-Nov-2012 15:50:23   

Yes, I am using Adapter and I've tried the method described in the forum below. It works for entities that are not derived from other entities. However, for subtype entities in TargetPerEntityHierarchy GetFieldPersistenceInfos() returns an empty array. Would I need to check if entity has supertype and pass the supertype to GetFieldPersistenceInfos()? What's the proper way to get the supertype's typename at runtime?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Nov-2012 20:42:58   

Which runtime library version (build no.) are you using?

AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 29-Nov-2012 18:15:37   

I am using 3.1.11.907

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Nov-2012 20:53:05   

Could you please try the latest release of v.3.1 And you may also try that of v.3.5

AlbertK
User
Posts: 44
Joined: 23-Dec-2009
# Posted on: 30-Nov-2012 20:00:38   

Tried latest 3.1 build 3.1.12.1015. Same problem. GetFieldPersistenceInfos() returns empty array. If I pass the superttype entity name, it works fine. Also works fine if entity is not subtyped.

Is there's a way to get the name of supertype name given entity name?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Dec-2012 06:44:24   

I think the code mentioned in the above referenced thread might be a downside when using it in a subtype. Please try this:

public partial class DataAccessAdapter
{
    public string GetTableName(IEntity2 entity)
    {
        return this.GetFieldPersistenceInfos(entity)[0].SourceObjectName;
    }
}

... at least it works here. If you still have problems please describe your inheritance hierarchy and what are the real tables behind them.

(Edit) Above code will fail if you use Inheritance per Entity Hierarchy with no additional fields on subtype. You better use something like thing:

return this.GetFieldPersistenceInfo(entity.PrimaryKeyFields[0]).SourceObjectName;
David Elizondo | LLBLGen Support Team