How to get the Primary Key(s) in Entity Framework 4.1, i.e. using DbContext
问题 The answers I'm seeing here are for ObjectContext. Is there a property to determine an entity's primary key names when using DbContext? Ah.. one of those times that I wish Entity Framework is open source! I can glean this primary key name information from .Find method :-) 回答1: You cannot use DbContext for that - DbContext API is just dumb wrapper with only most needed functionality. For everything more complex you must convert DbContext back to ObjectContext and use it. Try something like