Subsonic and AutomApper - DirtyColumns Collectionが空であるため、更新できません
-
14-11-2019 - |
質問
ASP.NET MVC3プロジェクトにSubsonic 3とAutomApperを使用しています。
私のhttppostのactionResultでは、私は自分のモデルを撮り、それをサブソニック生成されたエンティティにマッピングします。
マッピングは問題なく動作しませんが、エンティティを更新することはできません。
さらなる検査の際には、汚れた列がないため、サブソンが何も更新する必要があるとは思わないため、update()への通話は失敗します。
コードのロードを再編集しました - モデルに対するマッピング前に、デバイスからエンティティを再度ロードする方法を強制的に再編集しました。マッピングがDirtyColumns Trackingを破壊するようです。例えば。 DBからロード後にマップしてから、Randomプロパティを変更すると、ダーティ列としてマークされていません。
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()を呼び出して保存()を呼び出します。
どんなアイデアも大いに評価されます。私は彼らがAutomaPperによってエンティティに運ばれることを確認するために私のモデルにいくつかの追加のプロパティを置く必要があるかもしれないと考えています。
最悪の場合、吸うモデルからエンティティにマッピングするときは、AutomApperを使用しないでください。
解決
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 :)