Subsonic 및 Automapper - DirtyColumns 컬렉션이 비어 있으므로 업데이트 할 수 없습니다.
-
14-11-2019 - |
문제
ASP.NET MVC3 프로젝트에서 아바소니닉 3과 Automapper를 사용하고 있습니다.
내 httppost actionResult에서는 모델을 복용하고 아우 비 독신 엔티티로 매핑합니다.
맵핑은 Probs가 작동하지 않지만 엔티티를 업데이트 할 수 없습니다.
더 많은 검사를 통해 더러운 열이 없기 때문에 UPDATE에 대한 내 호출 ()이 실패합니다.
코드로드를 다시 조작했습니다. - 메소드가 모델에 대해 매핑하기 전에 DB에서 엔티티를 다시로드하는 방법을 강요합니다. 맵핑이 DirtyColumns 추적을 파괴하는 것처럼 보입니다. 예를 들어, DB에서로드 한 후 맵핑 한 다음 임의의 속성을 변경하면 더러운 열로 표시되지 않습니다.
SetIsLoaded (True) 메서드 호출을 사용하여 시도했습니다. 매핑 후 기쁨이 없습니다.
여기 내 방법이 있습니다 :
[HttpPost]
public virtual ActionResult Edit(SinglePersonModel model)
{
if (ModelState.IsValid)
{
Data.Person person;
//Now Map my model to my entity - this works
Mapper.CreateMap<SinglePersonModel, Data.Person>();
person = Mapper.Map<SinglePersonModel, Data.Person>(model);
//THIS DOESN'T SET MY COLUMN TO DIRTY
person.Link = "asdjsadij";
//THIS DOESN'T SET MY COLUMN TO DIRTY EITHER
person.SetIsLoaded(true);
person.Link = "asdjsadij";
if (person.PersonId > 0)
PersonRepository.UpdatePerson(person);
else
PersonRepository.CreatePerson(person);
return RedirectToAction(MVC.SecureAdministration.Person.Index());
}
else return View(model);
}
.
내 PersonRepository의 정적 메소드는 Subsonic의 Update ()를 호출하고 () 각각 저장합니다.
아이디어는 많이 감사 할 것입니다. 나는 이제 우리 모델에 추가적인 속성을 넣어 자동차에 electapper로 이월되었는지 확인해야 할 수도 있습니다.
최악의 경우는 모델에서 엔티티를 다시 매핑 할 때 자동 판매기를 사용하지 않아도됩니다.
해결책
AutoMapper.Mapper.Map<SinglePersonModel, Data.Person>(model, person);
- Have you tried it like this? This doesn't assign a new instance of the object but assigns it to the existing object. Just a thought. I understand the want of not loading it from the db. But figured this might help a bit :)
Thanks for that - glad to help out :)