2011-04-04 4 views
0

Est-ce ainsi que vous configurez une relation PK/FK de base?Entity Framework 4.1 Code d'abord - Touches/Propriétés de navigation

Avez-vous besoin de définir à la fois la clé et la propriété de navigation?

Public Class Foo 
    'PK 
    Public Property FooID As Integer 

    'Navigation Prop 
    Public Overridable Property Bars As ICollection(Of Bar) 

End Class 

Public Class Bar 
    'PK 
    Public Property BarID As Integer 
    'FK 
    Public Property FooID As Integer 

    'Navigation Prop 
    Public Overridable Property Foo As Foo 

End Class 

Répondre

2

Il s'agit d'une configuration de base si vous souhaitez que les conventions par défaut prennent en charge le mappage. Mais vous pouvez utiliser l'interface fluide et définir quoi que ce soit à partir de ces exemples comme relation valide:

propriété Navigation uniquement sur le parent:

Public Class Foo 
    'PK 
    Public Property FooID As Integer 

    'Navigation Prop 
    Public Overridable Property Bars As ICollection(Of Bar) 
End Class 

Public Class Bar 
    'PK 
    Public Property BarID As Integer 
End Class 

Navigation propety uniquement sur le parent et la propriété FK sur l'enfant:

Public Class Foo 
    'PK 
    Public Property FooID As Integer 

    'Navigation Prop 
    Public Overridable Property Bars As ICollection(Of Bar) 
End Class 

Public Class Bar 
    'PK 
    Public Property BarID As Integer 
    'FK 
    Public 
    Property FooID As Integer 
End Class 

Navigation sur la propriété de l'enfant:

Public Class Foo 
    'PK 
    Public Property FooID As Integer 
End Class 

Public Class Bar 
    'PK 
    Public Property BarID As Integer 

    'Navigation Prop 
    Public Overridable Property Foo As Foo 
End Class 

Propriété de navigation et propriété FK sur l'enfant:

Public Class Foo 
    'PK 
    Public Property FooID As Integer 
End Class 

Public Class Bar 
    'PK 
    Public Property BarID As Integer 
    'FK 
    Public Property FooID As Integer 

    'Navigation Prop 
    Public Overridable Property Foo As Foo 
End Class 

De plus, vous pouvez également faire en sorte que la realtion soit facultative.

Questions connexes