好的,我有这个配置在 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 列上设置身份规范。
知道为什么吗?
它与这些类实现的 IEntity 接口中指定的 Id 属性有什么关系吗?
如您在此处看到的,我已经尝试过 Data Annotation 方法和 Fluent API 方法。