【发布时间】:2015-07-27 10:49:01
【问题描述】:
关于如何双重映射这种父子关系的任何建议,其中父级具有正常的一对多关系(这是有效的),但是我需要从父级直接 1:1,0 链接到一个特定的孩子。
Public Class Source
<Key()>
Public Property SourceID As Int32
Public Property SourceFields As List(Of SourceField)
Public Property InboundMatchKeySourceFieldID As Nullable(Of Int32)
Public Property InboundMatchKeySourceField As SourceField
和
Public Class SourceField
<Key()>
Public Property SourceFieldID As Int32
Public Property SourceID As Int32
Public Property Source As Source
这是父/子映射(工作)
modelBuilder.Entity(Of Source).HasMany(
Function(S) S.SourceFields
).WithRequired(
Function(SF) SF.Source
).HasForeignKey(
Function(SF) SF.SourceID
)
这是我尝试额外的直接映射失败(不工作):
modelBuilder.Entity(Of Source
).HasOptional(
Function(S) S.InboundMatchKeySourceField
).WithRequired(
Function(SF) SF.Source
)
这会产生“MetaDataException”:
指定的架构无效。错误:关系 '_____.Source_InboundMatchKeySourceField' 未加载 因为类型 '_____.SourceField' 不可用。
【问题讨论】:
标签: entity-framework ef-code-first entity-framework-6 ef-fluent-api