【发布时间】:2020-01-03 00:13:54
【问题描述】:
我希望能够在删除影子外键属性的相关实体时更改行为。
public class Author
{
public int AuthorId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Book> Books { get; set; }
}
public class Book
{
public int BookId { get; set; }
public string Title { get; set; }
}
此设置将在图书实体中创建一个影子属性“AuthorId”,并且可以根据需要为空。
现在我希望当我删除一个作者时,所有相关书籍都将“AuthorId”外键设置为null。我怎样才能做到这一点?
【问题讨论】:
标签: c# entity-framework entity-framework-core