猿问

entityFrameworks 1:n 无法删除的问题,还请各位帮忙看下,谢谢了

我有两个模型,为CE  和DeviceInterface ,其中,CE 模型具有属性ICollection<DeviceInterface> DeviceInterfaces

之后我使用的是repository模式,现想删除掉CE 底下的多个DeviceInterface,我是这样做的

DeviceInterfaceRepository.Delete(DeviceInterfaceRepository.GetById(Id)); 

出现如下错误

AnalysisSNMPTest.entityFrameworkTesting.TestDeleteSub:System.InvalidOperationException : Adding a relationship with an entity which is in the Deleted state is not allowed.

在此之间,我没有使用其他Repository,特没有让entityFramework 读出CE 的模型
我被折磨了好久, Google出的方式好像都不是太管用,

各位拜托了,邮箱jicheng1014#gmail.com  先谢谢了

慕码人2483693
浏览 465回答 3
3回答

智慧大石

没有详细的代码,无法分析这个问题。

MM们

问题找到了,其实是Model里对另外的一个引用造成的干扰,谢谢站长
随时随地看视频慕课网APP
我要回答