有这么一个领域类
public class Task {
private Project project;
/// <summary>
/// 项目
/// int
/// </summary>
[BelongsTo("Project")]
public Project Project
{
get { return project; }
set { project = value; }
}
private IList childrens;
[HasMany(typeof(Task), Table = "Task", ColumnKey = "ParentTask")]
public IList Childrens
{
get { return childrens; }
set { childrens = value; }
}
private Task parentTask;
/// <summary>
/// 父任务
/// </summary>
[BelongsTo("ParentTask")]
public Task ParentTask
{
get { return parentTask; }
set { parentTask = value; }
}
private IList members;
[HasMany(typeof(Member), Table = "Member", ColumnKey = "Task")]
public IList Members
{
get { return members; }
set { members= value; }
}
}
这里我关注 private IList childrens;,,就是因为有这样一个关系存在,当Task在做更新(update)时候,除了发生本身的一个update外,,还会根据此关系发生'UPDATE Task SET ParentTask = null WHERE ParentTask = @p0', N'@p0 int', @p0 = 327681,,,这是因为task与自己的子task有一对多关系!!!
以上是主外键在一个表时,,当主外在不同表中时,,比如上面的一个任务对应多个成员时,在更新任务后,也会紧紧跟一句生'UPDATE Member SET Task = null WHERE Task = @p0', N'@p0 int', @p0 = 327643,
==================
注意:
但是对于外键所在对象做更新时候,,,只更新自己,与其他对象不在发生任何联系
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)