Lalji Kanjareeya
Lalji Kanjareeya

Reputation: 135

when breeze child entity update parent entity state is not change

knockout SPA

When I Add/Update child entity, parent entity state is not change.

following Scenario I have this is client side change tracking using breeze

public class Student
{
    public int StudentId { get; set; }
    public string Name { get; set; }
    public Department Department { get; set; }
}

public class Department
{
    public int DepartmentId { get; set; }
    public string DepartmentName { get; set; }
}

When I update 'Department' of 'Student', Student Entity state Remain 'Unchanged'.

How can i get Department Changes from 'Student' entity state.

Upvotes: 0

Views: 130

Answers (2)

Joel R Michaliszen
Joel R Michaliszen

Reputation: 4222

When you change the navigation property Department you don't change the entity Student because what made the change in this is the foregeing key of the Department, so if you want to get the state, you need to know that is not the entity state that was changed it was the relationship state that was changedd, so you can get the state of the ObjectContext like this:

To get the entries use this:

var objCtx = ((IObjectContextAdapter)ctx).ObjectContext;
//In your case use the EntityState.Modified
var objentr = objCtx.ObjectStateManager.GetObjectStateEntries(EntityState.Modified);

To change:

((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.
              ChangeRelationshipState(student, oldDepartment,
                                      c => c.Department, EntityState.Modified);

Update after explanation about the question:

So given that what I told about the navigation property Department was true to Breeze too, so see this section in the documentation Navigations properties - EntityState and PropertyChanged events after setting.

Upvotes: 1

Jonathan
Jonathan

Reputation: 245

Why don't you just add the DepartmentID property to the Student? When the Department is updated the DepartmentID will change as well and the EntityState will update.

Upvotes: 0

Related Questions