views:

27

answers:

1

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?

A: 

Updated my T4 template to add the following:

<#  if(ef.IsKey(edmProperty))
{
#>
[EdmScalarPropertyAttribute(EntityKeyProperty=<#=code.CreateLiteral(true)#>)]
<#
}
#>

Then used reflection to find the EntityKeys.

Brandon