Inserting entity doesn't update Key field

c# entity-framework graphdiff

Accepted Answer

Well, just before I posted the query, I learned thatUpdateGraph had a return type, but I never used it.

If the returned entity isn't used, the entity states will be correctly updated but the entity tracking will be completely broken.

Adapting myAddObject to this solved the problem :

public Foo AddObject(Foo entity)
{
    entity = UpdateGraph(entity);
    _context.SaveChanges();
    return entity;
}

public override Foo UpdateGraph(Foo entity)
{
    return DataContext.UpdateGraph(entity, map => map
        .AssociatedCollection(e => e.Bars)
        .AssociatedEntity(e => e.Baz)
    );
}
3
12/19/2014 10:29:05 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow