我想将虚拟对象(Details)设为null,我的示例类详细信息如下:
public class test
{
public List<stud> students{get;set;}
}
public class stud
{
public int id{get;set;}
public string name{get;set;}
[ForeignKey("Details")]
public int DetailId { get; set; }
[JsonIgnore]
public virtual Details Details{ get; set; }
}
public class Details
{
public string a {get;set;}
public string b{get;set;}
}
test.students= await db.students.where(x=>x.id==12).ToListAsync();
foreach(var a in test.students)
{
a.Details=null;
db.savechanges();//but the Details obj is not being set to null.
}
有人可以帮我设置详细信息obj为null吗?