0
我有这个表的情况实体框架6多重嵌套的主从嵌件
因此,大家可以看到有一个多层嵌套的主从表和我有一个requeriment,我要插入在前三个实体中,我使用实体框架6,数据库优先。 (mvc Web api2)。我设法以这种方式做前两个实体:
Entity1 entity1 = new Entity1()
{
Field = "a field"
};
entity1.Entity2.Add(new Entity2()
{
Field = "another field"
});
// ****************************** *
//且保存为:
using (var context = new backendEntities())
{
context.Entity1.Add(entity1);
context.SaveChanges();
}
而对于前两个实体保存好,但我不能或没有发现添加下一个实体(ENTITY3)的方式。所有主键都是身份自动数字。我怎样才能一次保存这三个实体?谢谢大家帮助。
你是什么意思的'Entity3',你也使用* Code-First *或* Model-First *? – Luiso
什么阻止你使用'entity2.Entity3.Add(..);'? –
@Luiso - 实体(1,2,3,4)是表格。我使用数据库优先。 –