Determine Primary Keys of an Entity using the Context in Entity Framework 4.0
I have several entities generated from my Entity Framework data model. In the .edmx file I can see the properties that are flagged as primary keys. My POCO's/custom context are generated from this and the T4 templates.
I am 开发者_如何学运维looking for a way to find out the primary keys of my entities using reflection with Entity Framework 4.0. Is there an attribute I need to setup to get set on my POCO's when they are generated? Is there a property in my context I can use to drill down and find this information?
Updated my T4 template to add the following:
<# if(ef.IsKey(edmProperty))
{
#>
[EdmScalarPropertyAttribute(EntityKeyProperty=<#=code.CreateLiteral(true)#>)]
<#
}
#>
Then used reflection to find the EntityKeys.
精彩评论