How to do this Relationship in Entity Framework using DataAnnotation not Fluent API
-
Dear All, I have 6 tables created from a class using EF Code First approach, and I'm wondering how to do the relationship between the tables using DataAnnotation, classes as follow:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.WebImports System.ComponentModel.DataAnnotations
Imports System.ComponentModel.DataAnnotations.SchemaPublic Class Customer
<Key, ScaffoldColumn(False)>
Public Property CustomerID() As Integer<Display(Name:="File No"), StringLength(6)> Public Property CustomerFileNo() As String <Required(ErrorMessage:="First Name is required")> <Display(Name:="First Name"), StringLength(20)> Public Property FirstName() As String <Display(Name:="Last Name"), StringLength(20)> Public Property LastName() As String <Display(Name:="Street"), StringLength(40)> Public Property Addr\_StreetName() As String <DefaultSettingValue("0")> Public Property MaritalStatusID() As Integer <DefaultSettingValue("0")> Public Property Addr\_AreaID() As Integer <DefaultSettingValue("0")> Public Property Wrk\_OccupationID() As Integer
End Class
Public Class MaritalStatus
<Key, ScaffoldColumn(False)>
Public Property MaritalStatusID() As Integer<Required(ErrorMessage:="Name Required")> <Display(Name:="Marital Status"), StringLength(10)> Public Property MaritalName() As String <DefaultSettingValue("1")> Public Property RecStatus() As Boolean
End Class
Public Class Area
<Key, ScaffoldColumn(False)>
Public Property AreaID() As Integer<Required(ErrorMessage:="Name Required")> <Display(Name:="Area Name"), StringLength(30)> Public Property AreaName() As String <DefaultSettingValue("1")> Public Property RecStatus() As Boolean
End Class
Public Class Occupation
<Key, ScaffoldColumn(False)>
Public Property OccupationID() As IntegerPublic Property OccupationName() As String
End Class
Public Class InvoiceHdr
<Key, ScaffoldColumn(False)>
Public Property InvoiceID() As IntegerPublic Property InvoiceNo() As String Public Property Amount() As Integer Public Property CustomerID As Integer
End Class
-
Dear All, I have 6 tables created from a class using EF Code First approach, and I'm wondering how to do the relationship between the tables using DataAnnotation, classes as follow:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.WebImports System.ComponentModel.DataAnnotations
Imports System.ComponentModel.DataAnnotations.SchemaPublic Class Customer
<Key, ScaffoldColumn(False)>
Public Property CustomerID() As Integer<Display(Name:="File No"), StringLength(6)> Public Property CustomerFileNo() As String <Required(ErrorMessage:="First Name is required")> <Display(Name:="First Name"), StringLength(20)> Public Property FirstName() As String <Display(Name:="Last Name"), StringLength(20)> Public Property LastName() As String <Display(Name:="Street"), StringLength(40)> Public Property Addr\_StreetName() As String <DefaultSettingValue("0")> Public Property MaritalStatusID() As Integer <DefaultSettingValue("0")> Public Property Addr\_AreaID() As Integer <DefaultSettingValue("0")> Public Property Wrk\_OccupationID() As Integer
End Class
Public Class MaritalStatus
<Key, ScaffoldColumn(False)>
Public Property MaritalStatusID() As Integer<Required(ErrorMessage:="Name Required")> <Display(Name:="Marital Status"), StringLength(10)> Public Property MaritalName() As String <DefaultSettingValue("1")> Public Property RecStatus() As Boolean
End Class
Public Class Area
<Key, ScaffoldColumn(False)>
Public Property AreaID() As Integer<Required(ErrorMessage:="Name Required")> <Display(Name:="Area Name"), StringLength(30)> Public Property AreaName() As String <DefaultSettingValue("1")> Public Property RecStatus() As Boolean
End Class
Public Class Occupation
<Key, ScaffoldColumn(False)>
Public Property OccupationID() As IntegerPublic Property OccupationName() As String
End Class
Public Class InvoiceHdr
<Key, ScaffoldColumn(False)>
Public Property InvoiceID() As IntegerPublic Property InvoiceNo() As String Public Property Amount() As Integer Public Property CustomerID As Integer
End Class
-
Please don't post the same question in multiple forums. You already have some responses at http://www.codeproject.com/Messages/4544387/How-to-do-this-Relationship-in-Entity-Framework-us.aspx[^].
Use the best guess
-
True .. but (frazzle-me) suggested to submit it in the VB forum so I may get the answer .. so I thought it's ok to do that. Anyhow thanks for the info.