2009-08-26 4 views
0

私はこれを簡潔かつ簡潔にしています。私はここに私のコントローラを持っEntity Frameworkを使用してモデルのバインドされたオブジェクトを保持する

... myCustomObjectは偉大に見える

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Edit(CustomObject myCustomObject) 
{ 
    ... 
} 

。しかし、私は、エンティティフレームワークを使用して、これを保存したい場合は、私はこのような何かをする必要があります...

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Edit(CustomObject myCustomObject) 
{ 
    CustomObject existingObject = repository.GetCustomObject(myCustomObject.ID); 

    // Set all the attributes of myCustomObject to existingObject 
    existingObject.SomeMapperFunction(myCustomObject) 

    repository.Save(); 
} 

は、私は、このマッピングexcersiseをやってから保つことができる方法はありますか?

答えて

0
[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Edit(int id) 
{ 
    CustomObject existingObject = repository.GetCustomObject(id); 

    TryUpdateModel(existingObject); 
    // You additionaly can check the ModelState.IsValid here 

    repository.Save(); 
} 
関連する問題