Created
May 27, 2013 08:55
-
-
Save vkobel/5655941 to your computer and use it in GitHub Desktop.
Simple method to retrieve the keys of an entity in EF. The thing here is to convert the dumb DbContext into a much more powerful ObjectContext.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable<string> GetPrimaryKeyNames<T>() { | |
ObjectSet<T> objCtx = (ctx as IObjectContextAdapter).ObjectContext.CreateObjectSet<T>(); | |
return objCtx.EntitySet.ElementType.KeyMembers.Select(k => k.Name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment