GraphDiff icon indicating copy to clipboard operation
GraphDiff copied to clipboard

Keep navigation properties of associated entities

Open ghost opened this issue 11 years ago • 2 comments

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?

ghost avatar Nov 19 '14 21:11 ghost

Might it be due to the missing virtual modifiers on your navigation properties?

josh-dastmalchi avatar Dec 02 '14 20:12 josh-dastmalchi

No doesn't make any difference. Looking at the code we only include the associated entity itself, but never its children.

ghost avatar Dec 06 '14 11:12 ghost