現在、Entity Framework v4エンティティに基づくリポジトリがあります(CRUDおよびGET操作が実装されています)。これらのエンティティに対応するビューモデルを作成中です。それらの間に変換/マッピングをどこに置くべきですか?コントローラで、またはリポジトリを変更して、そのメソッドでマッピングを実行し、ビューモデルタイプのオブジェクトに戻る(または受け入れる)ようにしますか?
私はこれをすべきですか
public ActionResult Index()
{
var person = new PersonRepository().Get();
var personViewModel = new PersonViewModel();
personViewModel.InjectFrom(person)
.InjectFrom<CountryToLookup>(person);
return View(personViewModel);
}
またはこれ
public ActionResult Index()
{
var personViewModel = new PersonRepository().Get(); // returns object of type PersonViewModel
// and move this to repository
// var personViewModel = new PersonViewModel();
// personViewModel.InjectFrom(person)
// .InjectFrom<CountryToLookup>(person);
return View(personViewModel);
}