我有两个类,一个继承自另一个。第一个显示数据的摘要视图(4 列以上),子项显示详细视图(40 列以上)。两个类都在访问同一个表并共享被访问的相同列。
我的子类可以从父类继承,所以我只需要在一个地方更改映射吗?我宁愿没有重复的代码猖獗。
例如:
Public Class Parent
Public Overridable Property MyProp As String
Public Overridable Property MyProp2 As String
End Class
Public Class Child : Inherits Parent
Public Overridable Property MyProp3 As String
End Class
我想做这样的事情:
Public Class ParentMapping
Inherits ClassMapping(Of Parent)
Public Sub New()
Me.Property(Function(x) x.MyProp, Sub(y) y.column("MyProp"))
Me.Property(Function(x) x.MyProp2, Sub(y) y.column("MyProp2"))
End Sub
End Class
Public Class ChildMapping
Inherits SubClassMapping(of Child)
Public Sub New()
' I want to be able to inherit the mappings of the parent here.
MyBase.New()
Me.Property(Function(x) x.MyProp3, Sub(y) y.column("MyProp3"))
End Sub
End Class