我会尽量保持简短和简洁。
我的控制器在这里...
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(CustomObject myCustomObject)
{
...
}
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();
}
有没有办法可以避免做这个映射练习?