winformsentity-frameworktelerik-open-access

context.savechanges impact - Telerik EF concept


i am encountering a scenario that is as follows.

i have two tables named parent and child.

Upon fetching data from database, i got 1 row against parent and 2 rows against child.

At this stage if i ​create new child and add it to context and apply save changes, so ​now my database contains 1 row against parent and 3 rows against child but my context only contains 2 rows against child...

Do i need to refresh whole context or only that child to get latest database childs record in context so that i can do other operations with newly added child during the entire operation.

Parent objparent = context.Parent( p => p.id = 4);
objparent.count(); //1
objparent.Child.count();//2

Child objchild = new Child();
objchild.name = "abc";
objchild.parentid = 4;

context.add(objchild);
context.savechanges();
//do i need to refresh whole context to have newly added child under given parent
//or i should only fetch all childs against parent id 4 and re-attach them to context

Solution

  • For future readers, I wanted to mark this question as solved, thanks Damyan Bogoev for his guidance.

    I have observed entity framework functionality that is the moment new record gets saved in database by invoking context.savechanges(), it will automatically be fetched by current context along with its identity id (sequence / newly inserted primary key) and had state set as 'managed loaded'

    Means i can use newly inserted row within current context without re-fetching / refreshing my context.