Defining the primary keys of an object using context in Entity Framework 4.0

I have several objects generated from my Entity Framework data model. In the .edmx file, I see properties marked as primary keys. My POCO / user context is generated from this and T4 templates.

I am looking for a way to find out the basic keys of my entities using reflection with Entity Framework 4.0. Is there an attribute that I need to configure to install on my POCO when they are generated? Is there a property in my context that I can use to drill down and find this information?

+3
source share
1 answer

T4, :

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

, EntityKeys.

+6

Source: https://habr.com/ru/post/1757027/


All Articles