2017-02-14 1 views
1

ASP.NET MVC ID를 사용하고 코드 첫 번째 방법을 사용하여 추가 테이블을 만들려고합니다. 예를 들어 내 기본 표는 Orders이며, 이는 AspNetUsers 표 (id)로 다시 참조되며 사용자 당 여러 주문을 저장할 수 있습니다. 기본 테이블의 별도 ID는 보조 테이블의 세부 주문 세부 정보에 연결됩니다.Entity Framework 코드 첫 번째 - 외래 키 관계

두 테이블 간의 관계를 구현하는 방법을 고민하고 있습니까? 누군가가 도와주세요 수 있다면, 덕분에

Public Class ApplicationUser 
Inherits IdentityUser 
    Public Overridable Property Orders() As Orders 
End Class 

Public Class Orders 
    Public Property Id As String 'Should link to Id in AspNetUsers Table 
    Public Property TimeandDate As Datetime 
    Public Property OrderNo As Integer 
    Public Overridable Property OrderLineDetail() As ICollection(Of OrderLineDetail) 
End Class 

Public Class OrderLineDetail 
    Public Property Description As String 
    Public Property Price As Decimal 
End class 

Public Class ApplicationDbContext 
    Inherits IdentityDbContext(Of ApplicationUser) 

    Public Sub New() 
     MyBase.New("DefaultConnection", throwIfV1Schema:=False) 
    End Sub 

    Public Property Orders() As DbSet(Of Orders) 

    Public Shared Function Create() As ApplicationDbContext 
     Return New ApplicationDbContext() 
    End Function 

End Class 
+0

그냥 [구글] (http://www.entityframeworktutorial.net/code-first 당신을하지는 왜 /foreignkey-dataannotations-attribute-in-code-first.aspx) 질문 제목? 데이터 주석 및 관례에 관한 많은 자료를 찾을 수 있습니다. –

답변

1

UR AspNetUsers 테이블이 시도 :

Public Property Orders As ICollection(Of Orders) 
     Get 
     End Get 
     Set 
     End Set 
    End Property 
관련 문제