0

OK、この構成で、OrderPage とその子 OrderPageShipDate インスタンスのコレクションとの間の識別関係を設定しています。

public class OrderPageShipDateConfiguration : EntityTypeConfiguration<OrderPageShipDate>
{
    public OrderPageShipDateConfiguration()
    {
        this.HasKey(t => new { t.OrderPageId, t.Id });
        this.Property(p => p.OrderPageId).HasColumnOrder(1);
        this.Property(p => p.Id).HasColumnOrder(2)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        this.HasRequired(opi => opi.OrderPage)
            .WithMany(op => op.ShipDates)
            .HasForeignKey(opi => opi.OrderPageId);
    }

これらの参加者と:

/// <summary>
/// This class represents a a set of items added to an order from a particular bulletin at a particular time.
/// </summary>
public class OrderPage : IEntity, IAuditInfo
{       
    #region Construction
    //...
    #endregion

    public int Id { get; set; }

    // other properties...

    public virtual ICollection<OrderPageShipDate> ShipDates { get; set; }
}

_

/// <summary>
/// This class represents a shipping date for an order page that has been added to an order.
/// </summary>
public class OrderPageShipDate : IEntity
{
    #region Construction
    // ...
    #endregion

    public int Id { get; set; }

    public int OrderPageId { get; set; }

    public virtual OrderPage OrderPage { get; set; }

    public DateTime ShipDate { get; set; }
}

OrderPageShipDate テーブルの Id 列に設定された ID 仕様を取得できません。

理由はありますか?

これらのクラスが実装する IEntity インターフェイスで指定されている Id プロパティと何か関係があるのでしょうか?

ここにあるように、データ注釈アプローチと Fluent API アプローチの両方を試しました。

4

2 に答える 2

1

慣例により、EF は Id をキーとして取得し、id 属性を配置する必要があります。this.HasKey(t => new { t.OrderPageId, t.Id }) が問題かもしれません。ここで複合キーが必要ですか?

于 2013-09-24T22:26:17.393 に答える