如何使用 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; }
}