저는 처음으로 EF Code First를 사용하고 있으며, 내 타입 간의 관계를 추론하는 데 어려움을 겪고 있습니다. 이러한 두 가지 유형을 감안할 때 :EF 코드 문제 첫 번째 외래 키 추론
<Table("grpGroupType")>
Public Class GroupType
<Key()>
Public Property GroupTypeID As Integer
<Required()>
Public Property IsActive As Boolean
<Required()>
<MaxLength(100)>
Public Property Description As String
Public Overridable Property GroupDefinitions() As ICollection(Of GroupDefinition)
End Class
및
<Table("grpGroupDefinition")>
Public Class GroupDefinition
<Key()>
Public Property GroupDefinitionID As Integer
<Required()>
Public Property GroupTypeID As Integer
<Required()>
Public Property IsActive As Boolean
<Required()>
Public Property ScopeValue As Integer?
<Required()>
<MaxLength(100)>
Public Property Description As String
Public Overridable Property GroupType As GroupType
End Class
내가로드하고 DbContext 클래스를 사용하여 데이터를 저장할 수 있습니다,하지만 난 GroupType.GroupDefinitions 또는 GroupDefinition.GroupType에 액세스 할 때, 그들은 둘 다 아무 것도 반환하지 않습니다.
Public Class PD
Inherits DbContext
Public Property GroupDefinitions As DbSet(Of GroupDefinition)
Public Property GroupTypes As DbSet(Of GroupType)
Protected Overrides Sub OnModelCreating(ByVal modelBuilder As ModelConfiguration.ModelBuilder)
modelBuilder.Entity(Of GroupDefinition)().HasKey(Function(b) b.GroupDefinitionID)
modelBuilder.Entity(Of GroupType)().HasKey(Function(b) b.GroupTypeID)
End Sub
End Class
키 추론에 많은 문서가있는 것 같지 않습니다,하지만 난이 blog post을 발견했고, 내 클래스가 자동 추론 규칙을 따르는 것이 나타납니다 내 DbContext 클래스는 여기에있다.
누구나 올바른 방향으로 나를 가리킬 수 있습니까?
예상대로 작동하지 않는 코드를 표시하십시오. 감사. –