【发布时间】:2011-11-08 07:40:11
【问题描述】:
我正在尝试首先建立一对一的关系 EF v4.1 代码。这是我的代码:
public class System
{
[Key, ForeignKey("Station") ]
public int Id { get; set; }
[DisplayName("Last Polled")]
public DateTime? LastPolledOn { get; set; }
public virtual Station Station { get; set; }
}
public class Station
{
public int Id { get; set; }
public int Status { get; set; }
public string FullName
{
get
{
return StoreNumber + " - " + StoreName;
}
}
public virtual System System{ get; set; }
}
这很好,但是当我删除 Station 时,我得到级联删除错误:
"无法删除主键值,因为对该键的引用仍然存在。[外键约束名称 = System_Station]"}"
我应该怎么做才能解决这个问题?
【问题讨论】:
标签: c# entity-framework entity-framework-4.1 ef-code-first code-first