Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 实体框架是否提供用另一个脏图更新一个图的功能_Entity Framework_Dbcontext - Fatal编程技术网

Entity framework 实体框架是否提供用另一个脏图更新一个图的功能

Entity framework 实体框架是否提供用另一个脏图更新一个图的功能,entity-framework,dbcontext,Entity Framework,Dbcontext,EntityFramework(6)中是否有类似UpdateComplexObject的方法?我必须自己写这个方法吗 我希望该方法使用新的graph NewsToFanimals修改/删除/添加到Zoo.Animals()返回的graph Animals newSetOfAnimals = GetNewSetOfAnimalsMock(); ZooContext _db = new ZooContext(); // Inherits from db context Zoo zoo = _db.

EntityFramework(6)中是否有类似UpdateComplexObject的方法?我必须自己写这个方法吗

我希望该方法使用新的graph NewsToFanimals修改/删除/添加到Zoo.Animals()返回的graph

Animals newSetOfAnimals = GetNewSetOfAnimalsMock();

ZooContext _db = new ZooContext(); // Inherits from db context
Zoo zoo = _db.Zoo().Include(x=>x.Animals).First();


_db.UpdateComplexObject(Zoo.Animals(),newSetOfAnimals); 

_db.SaveChanges(); //the database should be consistent after this method with the newSetOfAnimals graph

您可以使用_db.Animals.Remove和_db.Animals.Add,但这需要循环