2013-08-31 15 views
6

私は間違いなくここに明白な何かを紛失しています。これは私が作成した最初のフロントエンドアプリケーションです。Breeze.js 1対多のリレーションシップでエンティティを削除する適切な方法

シナリオは次のとおりです。私は親子関係(1対多)を持っています。私は子供を作成することができますが、削除は失敗します。私は子供を作成し、それを保存、私は私が手を削除する場合:

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 ] 

私は削除がサーバーに送信されたとき、子供が「修正」の0と実体状態ののParentIDを持っていることを通知しました。私はこれが "削除される"と期待します。

関連するビューモデルの一部:

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:

<section data-bind="with: parent"> 
    <div data-bind="foreach: children"> 
    <div> 
     <select name="propertyOne" 
     data-bind="options: propertyOneOptions, value: propertyOne, optionsText: 'description', optionsCaption: 'Select a Property'"> 
     </select> 
     <button data-bind="click: $root.deleteChild">Delete Child</button> 
    </div> 
    </div> 
    <button data-bind="click: $root.addChild">Add Child</button> 
</section> 
<button data-bind="click: save">Save</button> 

データモデル:

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; } 
} 

答えて

7

実際に私が正しくエンティティを削除されませんでした。私が持っている必要があります。

child.entityAspect.setDeleted(); 

私は私が正しくchange tracking文書を読んでいたが、実際には、私はないと思っていました。

関連する問題