我有以下型号:
Public MustInherit Class Epreuve
Public Enum EpreuveType
CourseStade = 1
ConcoursSansBarre = 2
ConcoursAvecBarre = 3
EpreuveMultiple = 4
EpreuveCombinee = 5
End Enum
Public Property EpGuid As Guid
Public Property FormatPerf As String
Public Property CodeAppel As String
Public Property Nom As String
Public Property NomReduit As String
Public Property Chrono As String
Public Property Vent As Boolean
Public Property Ajustement As Double
Public MustOverride ReadOnly Property TypeEpreuve As EpreuveType
End Class
Public MustInherit Class EpreuveStade
Inherits Epreuve
End Class
Public MustInherit Class EpreuveComposee
Inherits EpreuveStade
Implements ISousEpreuve
Public Property EpParentGuid As Guid Implements ISousEpreuve.EpParentGuid
Public Property SousEpreuves As ObservableCollection(Of EpreuveStade) Implements ISousEpreuve.SousEpreuves
End Class
Public Class EpreuveCombinee
Inherits EpreuveComposee
Public Property EpreuveParent As EpreuveComposee
Public Overrides ReadOnly Property TypeEpreuve As EpreuveType
Get
Return EpreuveType.EpreuveCombinee
End Get
End Property
End Class
EpreuveComposee和EpreuveStade有许多可能的关系。 以下是我已经完成的流畅API:
With modelBuilder.Entity(Of Epreuve)
.HasKey(Function(ep) ep.EpGuid)
.Property(Function(ep) ep.EpGuid).HasDatabaseGeneratedOption(ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)
.Map(Of EpreuveCombinee)(Function(f) f.Requires("TypeEpreuve").HasValue(DirectCast(Epreuve.EpreuveType.EpreuveCombinee, Integer)))
End With
With modelBuilder.Entity(Of EpreuveCombinee)
.HasRequired(Function(f) f.EpreuveParent).WithMany.HasForeignKey(Function(f) f.EpParentGuid)
End With
当我尝试添加迁移时,出现以下错误:
外键组件' EpParentGuid'不是声明的财产 键入' EpreuveCombinee'。验证它是否未明确 从模型中排除,并且它是一个有效的原始属性。
答案 0 :(得分:0)
我找到了它。
Public MustInherit Class EpreuveComposee
Inherits EpreuveStade
Implements ISousEpreuve
Public Property EpParentGuid As Guid Implements ISousEpreuve.EpParentGuid
Public Property EpParent As Epreuve Implements ISousEpreuve.EpParent
Public Property SousEpreuves As ObservableCollection(Of Epreuve) Implements ISousEpreuve.SousEpreuves
End Class
Public Class EpreuveCombinee
Inherits EpreuveComposee
End Class
流畅的API:
With modelBuilder.Entity(Of EpreuveComposee)
.HasMany(Function(f) f.SousEpreuves).WithMany().Map(Sub(m)
m.ToTable("EpreuveSousEpreuves")
m.MapLeftKey("EpGuid")
m.MapRightKey("EpParentGuid")
End Sub)
End With