Saturday, 31 August 2013

Breeze.js proper method deleting entity in one to many relationship

Breeze.js proper method deleting entity in one to many relationship

Breeze 1.4.0, given the data model below, how to do I delete a child?
I am trying to use:
parent.children.remove(child);
but the update that is being sent to the server has a parentid of 0 and
entity state of "modified". The end result is an exception:
A foreign key value cannot be inserted because a corresponding primary key
value does not exist. [ Foreign key constraint name =
FK_dbo.Children_dbo.Parents_ParentId ]
What am I missing?
Data Model:
public class Parent
{
public Parent()
{
Children = new List<Child>();
}
[Key]
public int Id { get; set; }
public String OtherProperty { get; set; }
public IList<Child> Children { get; set; }
}
public class Child
{
[Key]
public int Id { get; set; }
public int ParentId { get; set; }
[ForeignKey("ParentId")]
public Parent Parent { get; set; }
}

No comments:

Post a Comment