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)?

4

1 回答 1

1

这应该有效:

  1. 为设计器中的映射属性选择一个不同的名称(例如employee_name_private)并将设计器中的 setter 和 getter 标记为Private
  2. 在部分类文件中定义具有所需属性的公共属性:

    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
    
于 2013-08-21T12:51:45.907 回答