I am trying to get the ID field name (property name) of an entity, is it possible?
User user= new User(); //User is an Entity
string idField = ??????? //user.UserId
I am trying to get the ID field name (property name) of an entity, is it possible?
User user= new User(); //User is an Entity
string idField = ??????? //user.UserId
You could merge both funcs into one or set your search conditions.
This post in the Entity Framework support forums shows how to use reflection to find ID fields and their details.
Entity class is still a class which inherits from System.Data.Objects.DataClasses.EntityObject, so, i think reflection will still work on it.
Have you tried it? Do you get any error?
If you can get the EntitySet, or the EntityType, for the entity, then you can use the KeyMembers property:
You can obtain a generic object set from the context: