Finding PK field at runtime

Posts   
 
    
Posts: 7
Joined: 26-Jul-2007
# Posted on: 26-Jul-2007 14:17:24   

How can I find the primary key field of an entity type at runtime?

I'm presuming there is a method/property somewhere in the object matrix of the entity objects, but I haven't been able to find it.

I have no issue using reflection if that's the best/only way of doing this.

An example: Given UserEntity with fields: id (PK), firstname, lastname. I need to find that the 'id' property is the primary key field.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jul-2007 15:17:08   

You have the EntityField.IsPrimaryKey property. And each entity contains the Fields property, which is an EntityField collection.