Customize Code Generation in EF: VB.NET: Search Metadata Properties: Listing 1
The NoDataMember method searches the metadata properties of the current item. There is a metadata property for all EDMX annotations, which are XML attributes on the Property or EntityType elements. The calling code adds the returned list to the AdditionalAttributes property of the event arguments of the OnPropertyGeneration event.
Private Const InstructionsEdmxAttributeName As String = _
"http://kadgen.com/edmx/Annotations:Instructions"
Private Const InstructionNoDataMember As String = _
"NoDataMemberAttribute"
Private Const RemoveDataMemberClrAttributeName As String = _
"RemoveDataMemberAttribute"
Private Function NoDataMember(ByVal item As MetadataItem) _
As IList(Of CodeAttributeDeclaration)
Dim codeAttributeDeclarations As New List(Of _
CodeAttributeDeclaration)()
If item IsNot Nothing Then
Dim metadataProperties = From prop In _
item.MetadataProperties _
Where prop.Name = InstructionsEdmxAttributeName _
AndAlso prop.Value IsNot Nothing _
AndAlso prop.Value.ToString() = InstructionNoDataMember
If metadataProperties.Count > 0 Then
codeAttributeDeclarations.Add(GetNewClrAttribute( _
RemoveDataMemberClrAttributeName))
End If
End If
Return codeAttributeDeclarations
End Function