에 1을 참조 나는 다음과 같은 개체가 :자가 많은 관계
public class TravelCoverageType
{
public int Code { get; set; }
public virtual TravelCoverageType PreventedBy { get; set; }
public ICollection<TravelCoverageType> PreventCoverages { get; set;}
...
}
각 TravelCoverageType
는 0 개 이상의 TravelCoverageType
의 방지 할 수 있습니다.
유창한 API를 사용하고 있지만이 관계를 설명하는 방법을 알 수 없습니다.
public TravelCoverageTypeConfiguration()
{
ToTable(ConfigConstants.TypeTablePrifix + typeof(TravelCoverageType).Name + "s");
HasKey(ct => ct.Code);
HasMany(tc => tc.PreventCoverages)
.WithOptional(tc=>tc.PreventedBy)
.HasForeignKey(tc => tc.Code);
}
그러나 나는 다음과 같은 오류 얻을 :
나는 시도했다
이System.Data.Entity.Edm.EdmAssociationType: : Multiplicity conflicts with the referential constraint in Role 'TravelCoverageType_PreventCoverages_Source' in relationship 'TravelCoverageType_PreventCoverages'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.
System.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'TravelCoverageType_PreventCoverages_Target' in relationship 'TravelCoverageType_PreventCoverages'. Because the Dependent Role refers to the key properties, the upper bound of the multiplicity of the Dependent Role must be '1'.
(나는 관계 간단하게 정의 할 PreventedBy
을 추가 한, 내가 정말 필요하지 않습니다를)
어떻게 완료 되나요?
:( –
답을 편집 – IronMan84
나는 importan 생각합니다. 여기서 part는 nullable 외래 키입니다. 유창한 코드를 사용하면 잘 작동합니다.저는 Sections라고 불리는 타입을 가지고 있습니다. (경로 => course.ParentId) .WillCascadeOnDelete (false) : HasOptional (section => section.Parent) – jwize