Javascript 删除一对多关系中实体的正确方法
我有亲子关系(一对多)。我可以创建子项,但删除失败。我创建一个子项,保存它,但当我删除它时,我得到:Javascript 删除一对多关系中实体的正确方法,javascript,entity-framework,breeze,Javascript,Entity Framework,Breeze,我有亲子关系(一对多)。我可以创建子项,但删除失败。我创建一个子项,保存它,但当我删除它时,我得到: 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 ] 我注意到,当删除发送到服务器时,子项的parentid为0
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 ]
我注意到,当删除发送到服务器时,子项的parentid为0,实体状态为“modified”。我希望这会被“删除”
相关视图模型部分:
function queryFailed(error) {
console.log('Query failed: ' + error.message);
}
function save() {
dataservice.saveChanges().fail(queryFailed);
}
function deleteChild(child) {
parent().children.remove(child);
}
function addChild() {
dataservice.createChild(parent);
}
HTML:
删除子项
添加子项
拯救
数据模型:
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; }
}
公共类父类
{
公共家长()
{
Children=新列表();
}
[关键]
公共int Id{get;set;}
公共字符串OtherProperty{get;set;}
公共IList子项{get;set;}
}
公营儿童
{
[关键]
公共int Id{get;set;}
public int ParentId{get;set;}
[ForeignKey(“ParentId”)]
公共父级{get;set;}
}
事实上,我没有正确删除实体。我应该:
child.entityAspect.setDeleted();
我以为我读对了文件,但事实上我没有
child.entityAspect.setDeleted();