实体框架将实体映射到自身

时间:2012-07-31 11:06:30

标签: entity-framework

我有一个实体需要包含自己的相关实体:

public class Period
{
public int ID {get; set;}
public DateTime StartDate {get; set;}
public DateTime EndDate {get; set;}  
public Period PriorPeriod {get; set;}  

}

如何仅使用POCO实现此目的,还是需要Fluent API映射?

1 个答案:

答案 0 :(得分:0)

public class Period
{
    public int ID { get; set; }
    public int? PriorPeriodID { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }

    [ForeignKey("PriorPeriodID")]
    public Period PriorPeriod { get; set; }
}