Shouldn't I be able to get the EntityKey object using the complex property method or property method for the DbEntityEntry. I couldn't find any examples MSDN, but I presume that this is possible in Entity Framework 5. I Will not know the name of the entity key or entity as I am using a generic repository interface.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
If you have a
DbEntityEntry
object you get theEntityKey
by first finding the wrappedObjectContext
:Then you can find the entity key by
EDIT
I created two extension methods that get you close to what you want:
Now you can do
or
The runtime will pick the right overload.
Note that the syntax that you proposed (
dbEntityEntryObject.Property<EntityKey>()
) can't work when the entity has a composite key. You have to get theEntityKey
from the entity itself.