我不确定删除Job时为什么没有删除FileList。 它仍然是数据库中的孤儿。
使用Entity Framework 6.0.0.0。 代码优先
modelBuilder.Entity<Job>()
.HasOptional(u => u.FileList)
.WithMany()
.HasForeignKey(j => j.FileListGuid)
.WillCascadeOnDelete(true);
[Table("Job")]
internal class Job : BaseEntity, IDeletable, IFileList
{
[Key]
public Guid Guid { get; set; }
[ForeignKey("FileList")]
public Guid? FileListGuid { get; set; }
public virtual FileList FileList { get; set; }
}
[Table("FileList")]
class FileList : BaseEntity
{
[Key]
public Guid Guid { get; set; }
public virtual ICollection<File> Files { get; set; }
}