在EntityFramework Code第一种方法中为外键指定null

时间:2016-11-01 11:03:33

标签: c#-4.0 entity-framework-6

我想将虚拟对象(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吗?

0 个答案:

没有答案