如何在 EF Core 中附加带有添加子的图形?
private static void AttachGraphWithExistingParentNewChild()
{
Class class;
using (var context = new SchoolContext())
{
class = context.Classes.FirstOrDefault(s => s.Name.Contains("AA"));
}
class.Students.Add(new Student{Name= "Youssef" });
using (var context = new SchoolContext())
{
context.ChangeTracker.TrackGraph(class, e=>e.Entry.State = EntityState.Added);
}
}
此方法将添加父项和子项,这不是真的,我只想添加子项并让父项保持不变。