Person has two similar tables, difference is that each person has only one record in PersonPreference table, but can have many in PersonRoles table. Both PersonPreference and PersonRole have the same primary and foreign key (Person_ID):
<Table("Person")> _
Public Class Person
<Key()> _
Public Property Person_ID As Integer
Public Property Name As String
Public Overridable Property PersonPreference As PersonPreference
Public Overridable Property PersonRoles As ObservableCollection(Of PersonRole)
End Class
<Table("PersonPreference")> _
Public Class PersonPreference
<Key()> _
Public Property Person_ID As Integer
Public Property Car As String
Public Property Color As String
End Class
<Table("PersonRole")> _
Public Class PersonRole
<Key()> _
Public Property Person_ID As Integer
Public Property Role As String
End Class
Public Class PersonMap
Inherits EntityTypeConfiguration(Of Person)
Public Sub New()
Me.HasRequired(Function(t) t.PersonPreference).WithRequiredPrincipal()
Me.HasRequired(Function(t) t.PersonRoles).WithRequiredPrincipal()
End Sub
End Class
Is there a way of saving the person roles as it is the code (without adding the Roles table) or there need to be modifications (primary key on PersonRoles table – I have tried making composite key in PersonRoles table, but that did not work)?
It is not necessary to have a
Roletable but you need to have a composite key inPersonRoletable. I not familiar with VB.net so hope you can convert this into VB.net.Here is an example