Keep navigation properties of associated entities
The returned entity from UpdateGraph does not contain navigation properties of associated entities, i.e. if we have
public class Foo {
[Key]
public int Id { get; set; }
public Bar Bar { get; set; }
public string Other { get; set; }
}
public class Bar {
[Key]
public int Id { get; set; }
public Baz Baz { get; set; }
}
public class Baz {
[Key]
public int Id { get; set; }
}
and do
var foo = new Foo {
Other = "Asdf",
Bar = new Bar {
Baz = new Baz()
}
};
using (var context = new TestContext()) {
var newObject = context.UpdateGraph(foo, map => map
.AssociatedEntity(x => x.Bar));
context.SaveChanges();
}
then afterwards newObject contains the correct IDs (and row versions), but foo.Bar.Baz is null.
The problem is, I now need another call to the database to get the complete updated entity (which is complicated) or manually copy elements around (which is what I try to avoid in the first place).
Is there any way to get around this?
Might it be due to the missing virtual modifiers on your navigation properties?
No doesn't make any difference. Looking at the code we only include the associated entity itself, but never its children.