1

I need to add some attributes to properties that were autogenerated by Entity Framework and do not want to lose them when regenerating objects. I don't want to touch T4 either.

Looking interenet I found that the partial class can be added MetaDataType like:

<MetadataType(GetType(Employee_Metadata))> _
Partial Public Class employee
...

And then create another class where we add the actual metadata to properties:

Public Class Employee_Metadata

    <Category("General"), DisplayName("Name"), Description("Employee name.")> _
    Public Property employee_name() As String
        Get
            Return _employee_name
        End Get
        Set(value As String)
            _employee_name = value
        End Set
    End Property
    Private _employee_name As String

End Class

Now, what else I need to do to get access to the attributes? I am currently binding a UI component to class employee autogenerated property "employee_name" (using MVVM). Do I need to change further something in my partial class or should I change the databinding itself (WPF in this case)?

1 Answer 1

1

This should work:

  1. Choose a different name for the mapped property in the designer (e.g. employee_name_private) and mark both setter and getter in the designer as Private.
  2. In a partial class file define the public property with the required attributes:

    Partial Public Class Employee
    
        <Category("General"), DisplayName("Name"), Description("Employee name.")> _
        Public Property employee_name() As String
            Get
                Return employee_name_private
            End Get
            Set(value As String)
                employee_name_private = value
            End Set
        End Property
    
    End Class
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.