流fluent APIとの1人の多くの関係をオプションの自己参照を定義します

StackOverflow https://stackoverflow.com/questions/9395009

  •  29-10-2019
  •  | 
  •  

質問

public class Attribute
{
    [Key]
    public int AttributeId { get; set; }

    [Required, StringLength(100)]
    public string Name { get; set; }

    public int ValueAttributeId { get; set; }
    public Attribute ValueAttribute { get; set; }

    public IList<Attribute> ValueAttributes { get; set; }
}

  modelBuilder.Entity<Attribute>()
     .HasOptional(a => a.ValueAttribute)
     .WithMany(a => a.ValueAttributes)
     .HasForeignKey(a => a.ValueAttributeId);

tsystem.data.entity.edm.edmassociationtype :: relationys astortiont_valueattribute 'の役割「属性_valueattribute_target」の参照制約との多重度の競合。依存する役割のすべてのプロパティは非無効であるため、主要な役割の多様性は「1」でなければなりません。

aaaaahhhh .....

役に立ちましたか?

解決

public int ? ValueAttributeId { get; set; }

...プロパティはヌル可能である必要がありました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top