gpt4 book ai didi

ef-code-first - ef 两个关系

转载 作者:行者123 更新时间:2023-12-01 05:28:13 28 4
gpt4 key购买 nike

我有以下 Entity Framework 5 代码第一类

public class Airplane
{
public int Id { get; set; }

public int LeftWingId { get; set; }
public virtual Wing LeftWing { get; set; }

public int RightWingId { get; set; }
public virtual Wing RightWing { get; set; }
}

public class Wing
{
public int Id { get; set; }
}

飞机有一个左翼和一个右翼(两者都是必需的)。机翼可能属于 0..1 飞机(作为左翼或右翼)或其他一些“飞行装置”。
删除飞机应该级联删除它的机翼。

如何在代码优先的流畅 API 中进行配置?

EF 中是否可以有两个 0..1 --- 1 关联,并在两者上进行级联删除?

最佳答案

不幸的是,您不能让两个关联从同一个源表指向同一个目标表,同时在两者上进行级联删除。

但是,这不是由于 EF 中的限制,而是由于 SQL 服务器中的限制。

引自 answer on another question你可能想检查:

SQL Server does simple counting of cascade paths and, rather than trying to work out whether any cycles actually exist, it assumes the worst and refuses to create the referential actions (CASCADE): you can and should still create the constraints without the referential actions. If you can't alter your design (or doing so would compromise things) then you should consider using triggers as a last resort.

关于ef-code-first - ef 两个关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12818043/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com