1

Is there a way to find Key Members of an entity (TEntity) when using CodeFirst (DbContext) on a generic context similar to ObjectContext?

I can see how it's done using ObjectContext here.

Community
  • 1
  • 1
imesh
  • 1,374
  • 1
  • 15
  • 18

1 Answers1

1

I'm sorry for the confusion, it seems like even with Code First approach we can find the key members on an entity using the object context as shown below:

var ObjectContext = ((IObjectContextAdapter)DbContext).ObjectContext;
var ObjectSet = ObjectContext .CreateObjectSet<TEntity>();
var EntitySet = ObjectSet.EntitySet;
var KeyMembers = EntitySet.ElementType.KeyMembers;
imesh
  • 1,374
  • 1
  • 15
  • 18