Creating Model relation in ASP.NET MVC 5 in VB

asp.net-mvc-5 entity-framework-6 vb.net

Accepted Answer

You need to refactor your code in order to accomplish the right relationship:

Public Class Band
   Public Property BandID() As Integer
   Public Property BandName() As String
   'This is the FK
   Public Property MusicStyleID() As Integer
   <ForeignKey("MusicStyleID")> 
   Public Property MusicStyleRef() As MusicStyle
End Class

Public Class MusicStyle
   Public Property MusicStyleID() As Integer
   Public Property MusicStyleName() As String
   Public Overridable Property Bands() As ICollection(Of Band)
End Class
1
10/28/2016 3:09:49 PM

Popular Answer

Thanks Hackerman! This still works if you simply refactor the Bands class. I'm not sure, however, whether this approach leaves out anything crucial that your code did.

Public Class Band
   Public Property BandID() As Integer
   Public Property BandName() As String
   Public Property MusicStyleID() As Integer
   Public Property MusicStyleRef() As MusicStyle
End Class

Public Class MusicStyle
   Public Property MusicStyleID() As Integer
   Public Property MusicStyleName() As String
End Class


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow