ここに私の問題があります、
Componet.cs に次のモデルがあります (私の実際のコンポーネントにはさらに 10 個の Icollection がありますが、ICollection が 1 つでも 10 でも問題は同じはずなので、書き留めません)。
public partial class Component
{
public Component()
{
this.BrandOwner = new HashSet<BrandOwner>();
this.Description = new HashSet<Description>();
}
public int GestCompID { get; set; }
public int ID { get; set; }
public Nullable<int> BaseGestCompID { get; set; }
public Nullable<int> BaseCompID { get; set; }
public string DefName { get; set; }
public string ProductRef { get; set; }
public virtual country country { get; set; }
public virtual language language { get; set; }
public virtual ICollection<BrandOwner> BrandOwner { get; set; }
public virtual ICollection<Description> Description { get; set; }
私のアプリケーションでは、その属性を追加、削除、または編集するために、そのコンポーネントを編集できます。国または言語に応じて、複数のブランド所有者または説明を追加できます。編集するコンポーネントの 1 つを選択すると、そのコンポーネントをセッション変数にロードし、そのセッション変数に対してすべてのアクションを実行します。
アイテムの編集が終了すると、Accept と Cancel の 2 つのボタンがあります。セッション変数で行われたすべての変更をキャンセルすると、破棄されます。
Accept ボタンを押して選択した項目を更新すると、問題が発生します。への道が見つからない
私のAcceptメソッドは次のとおりです。
public ActionResult AcceptChanges()
{
try
{
Component component = (Component)Session["component"];
GIEntities.Current.Component.Attach(component);
GIEntities.Current.SaveChanges();
Session["component"] = null;
return RedirectToAction("Index", new { Message = "correct" });
}
catch (DbUpdateException ex)
{
String error = ex.ToString();
Component component = (Component)Session["component"];
return RedirectToAction("EditComponent", new { id = componente.ID });
}
}
ステータスを Modified にアタッチ、追加、設定しようとしましたが、うまくいきません。また、コンポーネントを取り外して再度取り付けてみました。誰かが私が間違っていることを教えてもらえますか?
どうもありがとうございました。
私の悪い英語を申し訳ありません。