EF5を使用してエンティティを削除するにはどうすればよいですか?このエラーが発生します:
The object cannot be deleted because it was not found in the ObjectStateManager.
DbSetで.Removeを呼び出そうとしたとき。グーグルした後、私はそれを試しました
mycontext.Attach(entity)
mycontext.Remove(entity)
しかし、このようにして私は次のようになります。
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.
それで、それはObjectStateManagerにあるかどうか?!:)
私の実体はそのようなものです:
[Table("Words")]
public class Word : IWord
{
[Key, Required]
public int WordId { get; set; }
[Required, StringLength(50)]
public string Tag { get; set; }
//Foreign Key
public int VocabularyId { get; set; }
//Navigation
public virtual Vocabulary Vocabulary { get; set; }
public virtual Language Language { get; set; }
public virtual List<Translation> Translations { get; set; }
}