0

これらのエンティティをマップしようとしています:

 [Table("AAN_DigitalLib_Asset")]
    public class Asset
    {
    [Column("ID")]
    public int ID { get; set; }

    [Column("format_id")]
    public int FormatID { get; set; }

    [Column("person_id")]
    public int? PersonID { get; set; }

    [Column("publicationYear")]
    public int? PublicationYear { get; set; }

    public Person People { get; set; }

    //public virtual AssetKeyword AssetKeywords { get; set; }

    public virtual ICollection<AssetKeyword> AssetKeywords { get; set; }
}

これらのエンティティで:

[Table("AAN_DigitalLib_AssetKeyword")]
    public class AssetKeyword
    {
        [Column("ID")]
        public int ID { get; set; }

        [Column("asset_id")]
        public int AssetID { get; set; }

        [Column("keyword")]
        public string Keyword { get; set; }
    }

1 つAssetに複数のAssetKeywords. データベースにはリレーションシップが指定されていません。Fluent API を使用してリレーションシップを作成するにはどうすればよいですか?

4

1 に答える 1

1

追加しますか

[ForeignKey("AssetID")]
public virtual Asset Asset { get; set; }

AssetKeyword クラスで修正しますか?

それでもうまくいかない場合は、 onModelCreating() でこれを行います

modelBuilder.Entity<AssetKeyword>()
                    .HasRequired(p => p.Asset)
                    .WithMany()
                    .HasForeignKey(p => p.AssetID);
于 2012-12-13T15:30:21.743 に答える