1

1 つの子を持つエンティティがあり、それを更新する必要がありますが、TryUpdateModel メソッドでは、厳密に型指定されたオブジェクトを受け入れず (FormCollection のみを受け入れます)、更新しようとすると、次のエラーが発生します。 .

{"関係が AssociationSet 'FK__SG_Usuari__ID_Si__534D60F1' に追加または削除されています。カーディナリティの制約により、対応する 'SG_Usuario' も追加または削除する必要があります。"}

問題は、オブジェクト全体ではなく、id のみの子プロパティを formcollection にロードできないことです。

4

3 に答える 3

0

「作成」ステートメントは次のようになります。

    public ActionResult Edit(FormCollection  form)
    {

      Usuario usuario = new Usuario
             {
                 NomeUsuario = form["Usuario.NomeUsuario"],
                 IdeUsuario = form["Usuario.IdeUsuario"],
                 NumRegistroRM = form["Usuario.NumRegistroRM"],
                 SenUsuario = form["Usuario.SenUsuario"],
                 SituacaoUsuario = this.SituacaoUsuarioService.GetSituacaoUsuario(x => x.ID_SituacaoUsuario == Convert.ToInt32(form["Usuario.SituacaoUsuario"]// note that i have to retrieive the entire object... the "child"

             };

      this.UsuarioService.AddUsuario(usuario);
     }

編集ステートメントは次のようになります。

 TryUpdateModel(a, "Usuario", this.GetUsuarioWhiteList(), form.ToValueProvider()); // but the form contains only the id and I can't load the child in it nor pass the object.
于 2009-07-03T13:13:11.293 に答える
0

エンティティ フレームワークのモデルから直接更新をクリックすると、エンティティがすべての関係で自動的に更新されます。

于 2009-07-03T07:20:00.823 に答える
0

私は最近同じ問題を抱えていましたが、エンティティ デザイナーで子テーブルの外部キーのカーディナリティ比を 1:many から 0..1:many に変更したところ、問題なく解決できました。

于 2009-12-07T10:08:39.273 に答える